我正在使用 Eclipse 创建一个 Android 应用程序并尝试使用 aCursor
来查询 SQLite 数据库。我不知道是什么导致这个游标失败:
public List<Word> getAllWords() {
List<Word> words = new ArrayList<Word>();
Cursor cursor = db.query(TABLE_NAME, new String[] {FIELD_PRIMARY_DEFINITION}, null, null, null, null, null);
cursor.close();
return words;
}
当我运行此代码时,我的 Android 模拟器说程序已停止。当我注释掉光标行时,它运行良好。数据库存在,表存在,TABLE_NAME
包含正确的表名和FIELD_PRIMARY_DEFINITION
包含列名。我有什么遗漏会导致失败吗?
谢谢你。
我不熟悉 Logcat,我是 Android 开发的新手。但是我对我的应用程序名称进行了过滤,它显示了以下内容:
02-18 22:26:08.447: I/jdwp(20692): Ignoring second debugger -- accepting and dropping
02-18 22:26:15.107: W/Trace(20989): Unexpected value from nativeGetEnabledTags: 0
02-18 22:26:15.148: W/Trace(20989): Unexpected value from nativeGetEnabledTags: 0
02-18 22:26:15.187: D/AndroidRuntime(20989): Shutting down VM
02-18 22:26:15.187: W/dalvikvm(20989): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
02-18 22:26:15.247: E/AndroidRuntime(20989): FATAL EXCEPTION: main
02-18 22:26:15.247: E/AndroidRuntime(20989): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.source.wordCollector/com.source.wordCollector.MainActivity}: java.lang.NullPointerException
02-18 22:26:15.247: E/AndroidRuntime(20989): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-18 22:26:15.247: E/AndroidRuntime(20989): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-18 22:26:15.247: E/AndroidRuntime(20989): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-18 22:26:15.247: E/AndroidRuntime(20989): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-18 22:26:15.247: E/AndroidRuntime(20989): at android.os.Handler.dispatchMessage(Handler.java:99)
02-18 22:26:15.247: E/AndroidRuntime(20989): at android.os.Looper.loop(Looper.java:137)
02-18 22:26:15.247: E/AndroidRuntime(20989): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-18 22:26:15.247: E/AndroidRuntime(20989): at java.lang.reflect.Method.invokeNative(Native Method)
02-18 22:26:15.247: E/AndroidRuntime(20989): at java.lang.reflect.Method.invoke(Method.java:511)
02-18 22:26:15.247: E/AndroidRuntime(20989): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-18 22:26:15.247: E/AndroidRuntime(20989): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-18 22:26:15.247: E/AndroidRuntime(20989): at dalvik.system.NativeStart.main(Native Method)
02-18 22:26:15.247: E/AndroidRuntime(20989): Caused by: java.lang.NullPointerException
02-18 22:26:15.247: E/AndroidRuntime(20989): at com.source.dal.WordDAO.getAllWords(WordDAO.java:75)
02-18 22:26:15.247: E/AndroidRuntime(20989): at com.source.wordCollector.MainActivity.onCreate(MainActivity.java:23)
02-18 22:26:15.247: E/AndroidRuntime(20989): at android.app.Activity.performCreate(Activity.java:5104)
02-18 22:26:15.247: E/AndroidRuntime(20989): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-18 22:26:15.247: E/AndroidRuntime(20989): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)