最近开始得到一个相当奇怪的Catlog,它没有很好地描述出错的地方。
我发布在这里:http://pastie.org/9415113
第55行:
DebugCarTxt = (EditText) findViewById(R.id.DebugCar);
// you should instantiate 'DatabaseHandler' here
DatabaseHandler db = new DatabaseHandler(this); // "this" refer to the context
Car cars = db.getCurrentCar();
db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(),cars.get_image()));
//this is line 55 String rows= "id : "+ cars.get_id()+ " address : "+cars.get_address() + "postcode : "+cars.get_postcode()+" image : "+cars.get_image();
这是我的getCurrentCar(){};
public Car getCurrentCar() {
SQLiteDatabase db = getWritableDatabase();
String sql = "SELECT " + KEY_ID + "," + KEY_IMAGE + " FROM " + TABLE_CARS + " ORDER BY RANDOM() LIMIT 1";
Cursor cursor = db.rawQuery(sql, new String[] {});
Car car = null;
try {
if (cursor.moveToFirst()) {
car = new Car(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), cursor.getString(3));
}
}
finally {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
db.close();
}
return car;
}
我是否正确地假设它正在调用null,因为数据库中没有任何内容?
答案 0 :(得分:2)
您获得的其中一个值设置为null。
编辑:我的错,我相信这辆车是空的。 您应该检查是否有任何值设置为null:
if(car == null) { //and etc for other get method.
//Use Logs here to print error on logcat.
}
这有助于识别哪个值为空。
日志信息:http://developer.android.com/reference/android/util/Log.html