i writing app in want write status of checkbox, whenever click on alert dialog button getting null pointer exception, see below logcat report , code:
null pointer exception:
addlisteneronbutton(); params.add(new basicnamevaluepair("soption1", tv1.gettext().tostring()));
uploadactivity.java:
loginbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { savedata(); addlisteneronbutton(); } public void addlisteneronbutton() { tv1 = (textview) alertdialog.findviewbyid(r.id.textview1); checkbox chkios = (checkbox) alertdialog.findviewbyid(r.id.chkoption1); chkios.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { if (((checkbox) v).ischecked()) tv1.settext("true"); else tv1.settext("false"); } }); } private boolean savedata() { final alertdialog.builder ad = new alertdialog.builder(uploadactivity.this); ad.settitle("error!"); ad.seticon(android.r.drawable.btn_star_big_on); ad.setpositivebutton("close", null); string url = "http://10.0.2.2/res/uploadimage.php"; list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("sfilesname", file_name.gettext().tostring())); params.add(new basicnamevaluepair("simagename", image_name.gettext().tostring())); params.add(new basicnamevaluepair("spersonname", person_name.gettext().tostring())); params.add(new basicnamevaluepair("spersonemail", person_email.gettext().tostring())); params.add(new basicnamevaluepair("soption1", tv1.gettext().tostring())); string resultserver = gethttppost(url,params); log.d("entire string::", " " + resultserver); /*** default value ***/ string strstatusid = "0"; string strerror = "cannot upload image"; jsonobject c; try { c = new jsonobject(resultserver); strstatusid = c.getstring("statusid"); strerror = c.getstring("message"); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); }
logcat:
07-15 06:45:01.094: w/dalvikvm(789): threadid=1: thread exiting uncaught exception (group=0x40a71930) 07-15 06:45:01.115: e/androidruntime(789): fatal exception: main 07-15 06:45:01.115: e/androidruntime(789): java.lang.nullpointerexception 07-15 06:45:01.115: e/androidruntime(789): @ com.example.uploadactivity$2.savedata(uploadactivity.java:303) 07-15 06:45:01.115: e/androidruntime(789): @ com.example.uploadactivity$2.onclick(uploadactivity.java:267) 07-15 06:45:01.115: e/androidruntime(789): @ android.view.view.performclick(view.java:4204) 07-15 06:45:01.115: e/androidruntime(789): @ android.view.view$performclick.run(view.java:17355) 07-15 06:45:01.115: e/androidruntime(789): @ android.os.handler.handlecallback(handler.java:725) 07-15 06:45:01.115: e/androidruntime(789): @ android.os.handler.dispatchmessage(handler.java:92) 07-15 06:45:01.115: e/androidruntime(789): @ android.os.looper.loop(looper.java:137) 07-15 06:45:01.115: e/androidruntime(789): @ android.app.activitythread.main(activitythread.java:5041) 07-15 06:45:01.115: e/androidruntime(789): @ java.lang.reflect.method.invokenative(native method) 07-15 06:45:01.115: e/androidruntime(789): @ java.lang.reflect.method.invoke(method.java:511) 07-15 06:45:01.115: e/androidruntime(789): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 07-15 06:45:01.115: e/androidruntime(789): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 07-15 06:45:01.115: e/androidruntime(789): @ dalvik.system.nativestart.main(native method)
i think you not getting status of checkbox in textview, please use below code checked status, have written code simple activity change in way use in alertdialog box..
public class myandroidappactivity extends activity { private checkbox chkios ; textview tv1; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); addlisteneronbutton(); } public void addlisteneronbutton() { tv1 = (textview) findviewbyid(r.id.textview1); chkios = (checkbox) findviewbyid(r.id.chkios); chkios.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { //is chkios checked? if (((checkbox) v).ischecked()) tv1.settext("true"); else tv1.settext("false"); } }); } }
Comments
Post a Comment