最近开始收到一个相当奇怪的目录,它不能很好地描述出了什么问题。
我把它贴在这里: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 因为数据库中没有任何内容?
最佳答案
您获得的值之一设置为 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
关于java - 奇怪的目录没有提供任何解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24914624/