1

クエリからテキスト ビューの txt を設定したいのですが、「サイズ 1 のエラーでインデックス -1 が要求されました。誰か助けてもらえますか?

    Cursor information = db.rawQuery("select id as _id,description from poet where _id="+Peot_ID_for_db,null);
    TextView poet_info=(TextView)findViewById(R.id.Poet_info);
    poet_info.setText(information.getString(information.getColumnIndex("_id")));
//  poet_info.append(information.getString(information.getColumnIndex("description")));

このエラーを検索しましたが、Google で何も見つかりませんでした..あなたが私を助けてくれることを願っています..テーブルにはこのクエリと一致する行が 1 つしかないので、すべての行を取得するためにそのようなループや sth は必要ないと思います

4

2 に答える 2

3

最初は必ず moveTo 関数を使用してください。

あなたがそうするまで、それはあなたのために行を取得しません。

例:

http://developer.android.com/reference/android/database/Cursor.html#moveToNext()

スニペット:

StringBuilder sb = new StringBuilder();

while(information.moveToNext()) {
    sb.append(information.getString(information.getColumnIndex("_id"))+" ");
}

poet_info.setText(sb.toString());
于 2013-04-04T18:06:21.057 に答える