爲什麼這兩行代碼會拋出一個NPE?空指針創建SQLite數據庫
SQLiteDatabase db;
db = openOrCreateDatabase("TestingData.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
堆棧跟蹤:
08-23 10:33:14.285: ERROR/AndroidRuntime(1001): Caused by: java.lang.NullPointerException
08-23 10:33:14.285: ERROR/AndroidRuntime(1001): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
08-23 10:33:14.285: ERROR/AndroidRuntime(1001): at org.*****.android.CopyOfSQLLite.data(CopyOfSQLLite.java:14)
08-23 10:33:14.285: ERROR/AndroidRuntime(1001): at org.******.android.*****.****(****.java:200)
08-23 10:33:14.285: ERROR/AndroidRuntime(1001): at org.********.android.****.onCreate(DashboardPage.java:25)
08-23 10:33:14.285: ERROR/AndroidRuntime(1001): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-23 10:33:14.285: ERROR/AndroidRuntime(1001): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
你確定錯誤到了嗎? –
如果將最後一個設置爲null,爲什麼要使用3個參數的方法?還有一種方法只適用於參數。 (http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#openOrCreateDatabase(java.lang.String,%20android.database.sqlite.SQLiteDatabase.CursorFactory)) – RoflcoptrException