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.
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");
}
}
精彩评论