我在DBAdater.java类中尝试了这个查询:
public Cursor getUserName(int userId) {
Cursor c = db.query(REGISTER_TABLE, new String[] { REGISTER_ID,
REGISTER_UN }, REGISTER_ID + " = " +userId,null, null, null,
null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
或者
public Cursor get_user(int id) {
return db.query(REGISTER_TABLE,
new String[] { REGISTER_ID, REGISTER_UN }, REGISTER_ID + "="
+ "'" + id + "'", null, null, null, null, null);
}
Test.java 获取用户名
Cursor clogin = db.getUserName(userId);
Log.i("user name with repect to user id ", ""+clogin.getString(clogin.getColumnIndex(DBAdapter.RID)));
当我运行这个时,我得到这个错误:
04-30 14:18:52.925: E/AndroidRuntime(639): FATAL EXCEPTION: main
04-30 14:18:52.925: E/AndroidRuntime(639): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.linkplus/com.android.Hello.test.test}: java.lang.NullPointerException
04-30 14:18:52.925: E/AndroidRuntime(639): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
......
......
04-30 14:18:52.925: E/AndroidRuntime(639): Caused by: java.lang.NullPointerException
04-30 14:18:52.925: E/AndroidRuntime(639): at com.android.Hello.test.Profiles.getUserName(Profiles.java:63)
04-30 14:18:52.925: E/AndroidRuntime(639): at com.android.Hello.test.Profiles.onCreate(Profiles.java:51)
04-30 14:18:52.925: E/AndroidRuntime(639): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
请指出此代码的错误是什么。提前致谢。