在 AsyncTask 我读取数据库表(一个接一个)是这样的:
Cursor result = database.query("country", new String[] { "_id", "name", "var1", "var2", "var3", "var4", "rightanswer", "time1", "time2", "time3" }, "_id=" + id, null, null, null, null);
result.moveToFirst();
然后,我打印result.getColumnCount()
并收到 10。
但是当我尝试打印这样的数据时:
System.out.println(result.getString(result.getColumnIndex("name")));
System.out.println(result.getString(result.getColumnIndex("var1")));
System.out.println(result.getString(result.getColumnIndex("var2")));
System.out.println(result.getString(result.getColumnIndex("var3")));
System.out.println(result.getString(result.getColumnIndex("var4")));
System.out.println(result.getString(result.getColumnIndex("rightanswer")));
System.out.println(result.getString(result.getColumnIndex("time1")));
System.out.println(result.getString(result.getColumnIndex("time2")));
System.out.println(result.getString(result.getColumnIndex("time3")));
我收到错误AndroidRuntime(8279): FATAL EXCEPTION: AsyncTask #1
AndroidRuntime(8279): Caused by: java.lang.NullPointerException
但是,当我只打印前两列时,
System.out.println(result.getString(result.getColumnIndex("name")));
System.out.println(result.getString(result.getColumnIndex("var1")));
它完全正常工作。
我没有线索。
更新:
String createQuery = "CREATE TABLE country (_id integer primary key autoincrement,name, var1, var2,var3,var4,rightanswer, time1,time2,time3);";
db.execSQL(createQuery);