游标cursor = ManagedQuery(intent.getData().... 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(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个..它会对你有用
try this..it will work for you