如何解决该错误如何获取数组列表在Cursor对象中返回结果查询集。有一些常用的方法可以用于游标
public class DBAdapter {
Context c;
CluecatalogOpenHelper helper;
SQLiteDatabase db;
int flag=0;
public DBAdapter(Context ctx) {
super();
this.c = ctx;
helper=new CluecatalogOpenHelper(ctx);
}
public void openDB(){
db=helper.getWritableDatabase();
}
public void closeDB(){
db.close();
}
public void addRow(String name, byte[] data1) {
openDB();
ContentValues values = new ContentValues();
values.put("name", name);
values.put("object",data1);
db.insert("topsearch", null, values);
closeDB();
}
public void deleteRow(String name)
{
try {
db.execSQL("delete from topsearch where name = (?)",new String[]{""+name});
} catch (SQLException e) {
e.printStackTrace();
}
}
public Cursor showData(){
try{
Cursor c = db.query("topsearch", new String[]{"name","object"}, null, null,null, null,null);
return c;
}catch(Exception e) {
e.printStackTrace();
return null;
}}}
如何解决该错误
答案 0 :(得分:0)
我不确定你究竟在问什么,但是如果你问如何从Cursor对象和List中取出结果你会这样做:
List list = new ArrayList();
Cursor c = db.query("topsearch", new String[]{"name","object"}, null, null,null, null,null);
while(c.moveToNext())
{
//populate your return object from the cursor here
//i'm just making this part up
Obj obj = new Obj();
obj.setName(c.getString(0)); //0 being the column index
list.add(obj);
}
return list;