android - NullPointerException when trying to get data out of intent in onActivityResult -


i'm new android programming , have activity has imagebutton, when clicked, opens new activity results dialog theme. user enters data , clicks submit. need data out of intent update images on first activity. problem keep getting nullpointerexception when try access string in intent.

1st activity's onclick method:

public void opendetails(view view){          intent intent = new intent(this, finalanalysisdialog.class);         //add backstack         startactivityforresult(intent, 1);      } 

2nd activity (dialog themed):

@override     protected void oncreate(bundle savedinstancestate){         super.oncreate(savedinstancestate);         setcontentview(r.layout.final_analysis_activity);          windowmanager.layoutparams params = getwindow().getattributes();           //params.x = -100;           params.height = 500;           params.width = 600;           //params.y = -50;            this.getwindow().setattributes(params);          setrequestedorientation(activityinfo.screen_orientation_landscape);         //final??         final spinner dropdown = (spinner) findviewbyid(r.id.faresultsdropdown);         dropdown.setselection(2);          button submit = (button) findviewbyid(r.id.fasubmitbutton);         submit.setonclicklistener(new onclicklistener() {             //based on value of selected item dropdown (spinner), update             //progress status picture             @override             public void onclick(view v) {                 bundle bundle = new bundle();                 //dropdown.getselecteditemposition();                 string result = dropdown.getselecteditem().tostring();                 //string result = "in process";                 bundle.putstring("result", result);                  intent intent = new intent();                 //intent.putextras(bundle);                 intent.putextra("result", result);                 setresult(result_ok, intent);         finish();             }         }); 

then try string out:

@override     protected void onactivityresult(int requestcode, int resultcode, intent data){         super.onactivityresult(requestcode, resultcode, data);         if (resultcode==result_ok && requestcode==1){             //imagebutton mfapic = (imagebutton)home.getview().findviewbyid(r.id.minsstepimage);//andrology_home_fragment              imagebutton mfapic = (imagebutton)findviewbyid(r.id.minsstepimage);//andrology_home_fragment             view mhomefapic = (view)findviewbyid(r.id.malefa);//male_details             //do result             //intent dataresult = data.getdata();             //bundle bundle =dataresult.getextras();             //string result = bundle.getstring("result");              bundle extras = data.getextras();             string result = extras.getstring("result");             //string result = data.getstringextra();             if (result.equals("not started")){                 mfapic.setbackgroundresource(r.drawable.orange_process);                 mhomefapic.setbackgroundresource(r.drawable.orange_process);             }else if (result.equals("in process")){                 mfapic.setbackgroundresource(r.drawable.orange_process);                 mhomefapic.setbackgroundresource(r.drawable.orange_process);             }else if (result.equals("complete")){                 mfapic.setbackgroundresource(r.drawable.green_process);                 mhomefapic.setbackgroundresource(r.drawable.green_process);             }else if (result.equals("problem")){                 mfapic.setbackgroundresource(r.drawable.red_process);                 mhomefapic.setbackgroundresource(r.drawable.red_process);             }         } 

i've tried send static string "in process" see if problem might getting value out of spinner didn't work. i've searched similar questions can't seem work. missing? appreciated..

here's logcat:

05-09 14:26:31.133: e/androidruntime(4984): fatal exception: main 05-09 14:26:31.133: e/androidruntime(4984): java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1, result=-1, data=intent { (has extras) }} activity {com.example.seattleivf/com.example.seattleivf.tabactionbarhomeactivity}: java.lang.nullpointerexception 05-09 14:26:31.133: e/androidruntime(4984):     @ android.app.activitythread.deliverresults(activitythread.java:3179) 05-09 14:26:31.133: e/androidruntime(4984):     @ android.app.activitythread.handlesendresult(activitythread.java:3222) 05-09 14:26:31.133: e/androidruntime(4984):     @ android.app.activitythread.access$1100(activitythread.java:140) 05-09 14:26:31.133: e/androidruntime(4984):     @ android.app.activitythread$h.handlemessage(activitythread.java:1276) 05-09 14:26:31.133: e/androidruntime(4984):     @ android.os.handler.dispatchmessage(handler.java:99) 05-09 14:26:31.133: e/androidruntime(4984):     @ android.os.looper.loop(looper.java:137) 05-09 14:26:31.133: e/androidruntime(4984):     @ android.app.activitythread.main(activitythread.java:4895) 05-09 14:26:31.133: e/androidruntime(4984):     @ java.lang.reflect.method.invokenative(native method) 05-09 14:26:31.133: e/androidruntime(4984):     @ java.lang.reflect.method.invoke(method.java:511) 05-09 14:26:31.133: e/androidruntime(4984):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:994) 05-09 14:26:31.133: e/androidruntime(4984):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:761) 05-09 14:26:31.133: e/androidruntime(4984):     @ dalvik.system.nativestart.main(native method) 05-09 14:26:31.133: e/androidruntime(4984): caused by: java.lang.nullpointerexception 05-09 14:26:31.133: e/androidruntime(4984):     @ com.example.seattleivf.tabactionbarhomeactivity.onactivityresult(tabactionbarhomeactivity.java:197) 05-09 14:26:31.133: e/androidruntime(4984):     @ android.app.activity.dispatchactivityresult(activity.java:5347) 05-09 14:26:31.133: e/androidruntime(4984):     @ android.app.activitythread.deliverresults(activitythread.java:3175) 05-09 14:26:31.133: e/androidruntime(4984):     ... 11 more 

you r problem retrieving string bundle , no intent itself, try using:

string result = data.getstringextra("result"); 

or uncomment line:

//intent.putextras(bundle); 

and retrieve string tried to.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -