帮助SimpleCursorAdapter和ListView [英] Help with SimpleCursorAdapter and Listview
问题描述
我坚持SimpleCursorAdapter,我打电话给我的本地的SQLite数据库,并把它变成然后被传递给SimpleCursorAdapter光标。
有关同样的原因日志猫不断出现下面这个错误。我不知道是怎么回事,我一直在这6个小时,我没想到SimpleCursorAdapter会如此不难理解了。
05-28 19:47:27.524:ERROR / AndroidRuntime(9353):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.nyneaxis.android.mpg / COM。 nyneaxis.android.mpg.userInfo}:java.lang.IllegalArgumentException异常:列'_id'不存在
setArray();
rec.open();
光标C = rec.getAllVeh();
SimpleCursorAdapter适配器=新SimpleCursorAdapter(这一点,R.layout.userinfo,C,新的String [] {c.getString(1)},新的INT [] {R.id.nameTxtL});
this.setListAdapter(适配器);
rec.close();
//数据适配器
公共光标getAllVeh(){
尝试{
返回db.query(database_table,新的String [] {key_rowid,vehicle_name,
今年,厂家,型号,款式,VIN,板,笔记},NULL,NULL,
NULL,NULL,NULL);
}最后{ }
}
好吧,我已经修改了我的code到A rawQuery,我再次得到这个错误:
22 05-28:41:48.876:ERROR / AndroidRuntime(1359):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.nyneaxis.android.mpg / com.nyneaxis.android.mpg.userInfo}: android.database.CursorIndexOutOfBoundsException:指数-1要求,大小0
私有静态最后弦乐db_sel =SELECT ID作为_id,vehicle_name FROM车;公共光标getAllVeh(){
尝试{
返回db.rawQuery(db_sel,NULL);
/ *回报db.query(database_table,新的String [] {key_rowid,vehicle_name,
今年,厂家,型号,款式,VIN,板,笔记},NULL,NULL,
NULL,NULL,NULL); * /
}最后{ }
}
谢谢你们为所有您的帮助。我设法做到这一点的不同方式,它看起来像一个魅力的工作。如果任何人有任何问题或建议,让我知道。
光标C = rec.getAllVeh();而(c.moveToNext()){
串vehName = c.getString(1);
vehInfo.add(vehName);
}//把信息放到addapter的列表视图
适配器=新ArrayAdapter<串GT;(这一点,
android.R.layout.simple_list_item_single_choice,vehInfo);//适用适配器列表视图
list.setAdapter(适配器);
I am stuck with SimpleCursorAdapter, I am calling my local SQLite DB and putting it into a cursor which then is passed to the SimpleCursorAdapter.
For same reason the Log Cat keeps showing this error below. I have no idea what is going on and I have been working on this for 6 hours, I didn't think SimpleCursorAdapter would be so difficult to understand.
05-28 19:47:27.524: ERROR/AndroidRuntime(9353): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nyneaxis.android.mpg/com.nyneaxis.android.mpg.userInfo}: java.lang.IllegalArgumentException: column '_id' does not exist
setArray();
rec.open();
Cursor c = rec.getAllVeh();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.userinfo, c, new String[]{c.getString(1)}, new int[]{R.id.nameTxtL});
this.setListAdapter(adapter);
rec.close();
//data adapter
public Cursor getAllVeh() {
try{
return db.query(database_table, new String[] { key_rowid, vehicle_name,
year, make, model, style, vin, plate, notes }, null, null,
null, null, null);
}finally{
}
}
Okay I have modified my code to a rawQuery and I get this error again:
05-28 22:41:48.876: ERROR/AndroidRuntime(1359): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nyneaxis.android.mpg/com.nyneaxis.android.mpg.userInfo}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
private static final String db_sel = "SELECT id as _id, vehicle_name FROM vehicle";
public Cursor getAllVeh() {
try{
return db.rawQuery(db_sel, null);
/*return db.query(database_table, new String[] { key_rowid, vehicle_name,
year, make, model, style, vin, plate, notes }, null, null,
null, null, null);*/
}finally{
}
}
Thanks guys for all you help. I managed to do it a different way and it seems to work like a charm. If anyone has any question or suggestions let me know.
Cursor c = rec.getAllVeh();
while (c.moveToNext()) {
String vehName = c.getString(1);
vehInfo.add(vehName);
}
//put information into the addapter for listview
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice, vehInfo);
//applies adapter to listview
list.setAdapter(adapter);
这篇关于帮助SimpleCursorAdapter和ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!