0
我編寫一個提供程序並創建一個數據庫。當我調用ContentResolver.insert是好的,但ContentResolver.query失敗並返回null。ContentResolver.quer返回null-android
c=mContentResolver.query(uri, DatabaseContants.COLUMNS_FAVORITEPOI,null, null,DatabaseContants.PLACEID_FAVORITE+" DESC");
日誌是
06-02 03:31:34.235: E/AndroidRuntime(23134): FATAL EXCEPTION: main
06-02 03:31:34.235: E/AndroidRuntime(23134): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.example.providerdatabase/com.example.providerdatabase.PrivoterDatabaseActivity}: java.lang.NullPointerException
06-02 03:31:34.235: E/AndroidRuntime(23134): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2082)
06-02 03:31:34.235: E/AndroidRuntime(23134): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2107)
06-02 03:31:34.235: E/AndroidRuntime(23134): at android.app.ActivityThread.access$600(ActivityThread.java:139)
06-02 03:31:34.235: E/AndroidRuntime(23134): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
06-02 03:31:34.235: E/AndroidRuntime(23134): at android.os.Handler.dispatchMessage(Handler.java:99)
06-02 03:31:34.235: E/AndroidRuntime(23134): at android.os.Looper.loop(Looper.java:137)
06-02 03:31:34.235: E/AndroidRuntime(23134): at android.app.ActivityThread.main(ActivityThread.java:4812)
06-02 03:31:34.235: E/AndroidRuntime(23134): at java.lang.reflect.Method.invokeNative(Native Method)
06-02 03:31:34.235: E/AndroidRuntime(23134): at java.lang.reflect.Method.invoke(Method.java:511)
06-02 03:31:34.235: E/AndroidRuntime(23134): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-02 03:31:34.235: E/AndroidRuntime(23134): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-02 03:31:34.235: E/AndroidRuntime(23134): at dalvik.system.NativeStart.main(Native Method)
06-02 03:31:34.235: E/AndroidRuntime(23134): Caused by: java.lang.NullPointerException
06-02 03:31:34.235: E/AndroidRuntime(23134): at com.example.providerdatabase.DatabaseController.getCount(DatabaseController.java:47)
06-02 03:31:34.235: E/AndroidRuntime(23134): at com.example.providerdatabase.PrivoterDatabaseActivity.onCreate(PrivoterDatabaseActivity.java:62)
06-02 03:31:34.235: E/AndroidRuntime(23134): at android.app.Activity.performCreate(Activity.java:5008)
06-02 03:31:34.235: E/AndroidRuntime(23134): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
06-02 03:31:34.235: E/AndroidRuntime(23134): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2046)
06-02 03:31:34.235: E/AndroidRuntime(23134): ... 11 more
你能幫助我嗎?
異常來自'47'行的'DatabaseController'類中的'getCount()'方法。 – Luksprog
是的,getCount()中的查詢函數。 c = mContentResolver.query(uri,DatabaseContants.COLUMNS_FAVORITEPOI,null,null,DatabaseContants.PLACEID_FAVORITE +「DESC」);它返回null – Hilda
如果這是'DatabaseController'中的行'47',那麼再檢查'mContentResolver'是否爲'null'。 – Luksprog