Are you sure the uri coming into the method is not null?

On Tuesday, December 11, 2012 10:19:13 PM UTC-5, Hilda Chen wrote:

> public int getCount(Uri uri){
>         Cursor c=null;
>         int size=0;
>         if(uri.equals(DatabaseContants.CONTENT_URI_SETTING)){
>             c=mContentResolver.query(uri, 
> DatabaseContants.COLUMNS_SETTING,null, null,null);
>         }
>         else if(uri.equals(DatabaseContants.CONTENT_URI_FAVORITEPOI)){
>             Log.v(TAG,"ContentResolver is "+mContentResolver);
>             c=mContentResolver.query(uri, 
> DatabaseContants.COLUMNS_FAVORITEPOI,null, 
> null,DatabaseContants.PLACEID_FAVORITE+" DESC");
>             Log.v(TAG,"Cursor c is "+c);
>         }
>         if(c!=null&&c.getCount()>0)size=c.getCount();
>         c.close();
>         return size;
>     }
> the error appears in this function.
>
> 在 2012年12月12日星期三UTC+8上午11时13分55秒,Hilda Chen写道:
>>
>> Hi All:
>>   I create a datatbase with provider and get the data by content 
>> resolver.  when call ContentResolver.insert is ok, but 
>> ContentResolver.query fail.
>>      c=mContentResolver.query(uri, 
>> DatabaseContants.COLUMNS_FAVORITEPOI,null, 
>> null,DatabaseContants.PLACEID_FAVORITE+" DESC");
>>   it return null, and the ContentResolver is not null;
>>   the log is 
>>   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
>>
>> can you help me?
>> Thanks!
>> Hilda
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to