我编写了一个提供程序并创建了一个数据库。当我调用ContentResolver.insert时没问题,但ContentResolver.query失败并返回null。
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
你能帮助我吗?
答案 0 :(得分:0)
这是我的错。我不记得在break
语句的switch
方法中添加query
ContentProvider
。如果您有此错误,请仔细检查ContentProvider
的代码。