English 中文(简体)
特定行中读取精选字段时遇到的问题
原标题:Issues in reading a specfic field in a given row

我正试图用下面的代码获取给定身份识别码的相应标题

public String get_Title(int id){
        Cursor c = db.query(true, DATABASE_TABLE, new String[] {
                APP_TITLE,
                },
                KEY_ROWID + "="  + id,
                null,
                null,
                null,
                null,
                null);

                String Final = c.getString(0);

                return Final;

        }

我总是把指数导致的例外排除在外。 光标的IM对光标不好, 所以如果有人能帮助我在这里。 S: S

最佳回答

您必须在 string final = c.get String(0) call c.moveToFirst () c.moveToNext () /code> 之前,先隐含地定位于第一行 < / tring(0) < /code> 的位置,然后您才能将 Cursor 移动到第一行,然后从中获取数据 。

<强度 > EDIT:


<强>,所以它应该像这样:

if (c.getCount()) { // if there is some data
   c.moveToFirst();
   String Final = c.getString(0);
}
else {
   Toast.makeText(YourActivityName.this, "No data found", Toast.LENGTH_SHORT).show();
}

所以您写道您在 Cursor 的小介绍中工作不好:

If you execute any statement, always instance of Cursor class will be returned. It s version of a database cursor, it is used in many database systems.

Class Cursor have following few basic methods:
  • getCount() - to get how many rows is in actual cursor
  • moveToFirst(), moveToNext() etc. - for moving between rows
  • getColumnNames() - to get column names
  • getColumnIndex() - to get the zero-based index for the given column name...
  • getString(), getInt() etc. - to get data of requested column index
  • requery() - once again execute cursor
  • close() - to release resources of cursor.
  • and next...

有关光标工作的更多信息,您可以找到 这里

观 观 观

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...