游标cursor = ManagedQuery(intent.getData().... nullpointerexception

发布于 2024-10-30 01:06:21 字数 3469 浏览 3 评论 0原文

我的代码有错误

 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(intent)

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();  
    }

我不知道,但在此功能行中cursor=托管查询...。我有 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 中遇到错误,应用程序已停止。请告诉我如何修复它,我在这个论坛上看到很多帖子 - 但找不到任何可以帮助我的东西:( 问候,彼得。

i have code with error

 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 

and getContactInfo(intent)

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();  
    }

I don't know but in this funiction line cursor= managed query ... . i have NullPointerException ((( I don't know how to fix it.

here from 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

when intent started - i press backbutton (on phone) and i following error in logcat , app is stopped. Please tell me how to fix it, i see many post's on this forum - but can't find anything what can help me :(
Regards, Peter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心奴独伤 2024-11-06 01:06:21

试试这个..它会对你有用

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");
           }
}

try this..it will work for you

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");
           }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文