我有这个函数应该从数据库中按 ID 返回对象。虽然请求的 ID 有数据,但没有返回数据。有人可以帮我解决这个问题。
代码:
public ChildRecord getChild(int id) {
ChildRecord child = null;
Log.v("--", "success13s ");
Cursor c = database.rawQuery("SELECT * FROM child " + "WHERE childID="
+ id, null);
Log.v("--", "success1 2");
if (c != null)
if (c.moveToFirst()) {
do {
int childid = c.getInt(0);
String parent1 = c.getString(1);
String parent2 = c.getString(2);
String name = c.getString(3);
String dob = c.getString(4);
int gender = c.getInt(5);
String height = c.getString(6);
String weight = c.getString(7);
String etnicity = c.getString(8);
int type = c.getInt(9);
child = new ChildRecord(childid, name, dob, gender, height,
weight, etnicity, type, parent1, parent2);
} while (c.moveToNext());
}
Log.v("--", "success1 ");
return child;
}
问题出在一线
Cursor c = database.rawQuery("SELECT * FROM child " + "WHERE childID="
+ id, null);