游标光标= managedQuery(intent.getData().... nullpointerexception

时间:2011-04-05 10:57:09

标签: android android-activity cursor nullpointerexception

我的代码有错误

 public void runIntent()
    {
         Intent intent = new      Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
         startActivityForResult(intent, 1);

    }
   public void onActivityResult(int requestCode, int resultCode, Intent intent) 
    {

               if (resultCode == 0) {
                getContactInfo(intent); 
                Log.e("RESULT_OK","Ok");
               }else
               {
                   Log.e("RESULT_OK","Error");
               }
    }//onActivityResult 

和getContactInfo(意图)

public void getContactInfo(Intent intent)
    {   
        Cursor cursor =  managedQuery(intent.getData(), null, null, null, null);  //i think error here becouse when i delete this i not have error.
cursor.close();  
    }

我不知道但是在这个游戏行游标=托管查询....我有NullPointerException(((我不知道如何解决它。

来自logcat:

04-05 10:48:53.055: ERROR/AndroidRuntime(620): FATAL EXCEPTION: main
04-05 10:48:53.055: ERROR/AndroidRuntime(620): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {contactTest.com/contactTest.com.ContactTest}: java.lang.NullPointerException
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at android.app.ActivityThread.access$2800(ActivityThread.java:125)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at android.os.Looper.loop(Looper.java:123)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at java.lang.reflect.Method.invokeNative(Native Method)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at java.lang.reflect.Method.invoke(Method.java:521)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at dalvik.system.NativeStart.main(Native Method)
04-05 10:48:53.055: ERROR/AndroidRuntime(620): Caused by: java.lang.NullPointerException
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at contactTest.com.ContactTest.getContactInfo(ContactTest.java:71)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at contactTest.com.ContactTest.onActivityResult(ContactTest.java:61)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at android.app.Activity.dispatchActivityResult(Activity.java:3890)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
04-05 10:48:53.055: ERROR/AndroidRuntime(620):     ... 11 more
04-05 10:48:53.085: WARN/ActivityManager(60):   Force finishing activity contactTest.com/.ContactTest

当意图开始时 - 我按下后退按钮(在手机上)并且我在logcat中跟随错误,应用程序停止。请告诉我如何解决它,我在这个论坛上看到很多帖子 - 但找不到任何可以帮助我的东西:( 问候,彼得。

1 个答案:

答案 0 :(得分:2)

试试这个..这对你有用

public void runIntent()
{
     Intent intent = new
Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
     startActivityForResult(intent, 1);

}
public void onActivityResult(int requestCode, int resultCode, Intent intent) 
{

           if (resultCode == RESULT_OK) {
            getContactInfo(intent); 
            Log.e("RESULT_OK","Ok");
           }else
           {
               Log.e("RESULT_OK","Error");
           }
}