0

我编写了一个提供程序并创建了一个数据库。当我调用 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

你能帮助我吗?

4

1 回答 1

0

这是我的错误。我不记得breakswitch. 如果您有此错误,请仔细检查您的代码。queryContentProviderContentProvider

于 2012-12-13T09:24:47.953 回答