setText("") android error group=0x4001b188 -
i got problem when make edit text empty when button clicked. ddms said error uncaught exception group=0x4001b188. here y code
public class main extends activity { float fm_value_pdty; button calc_fm_pdty, dt_pdty_calc, loader_pdty_calc; textview fm_value_pdty_txt; edittext dt_count, loader_count; public edittext dt_pdty; public edittext loader_pdty; public static float vdtpdty; public static float vloaderpdty; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); fm_value_pdty=(float) 0; calc_fm_pdty = (button) findviewbyid(r.id.calcpdty); dt_pdty_calc = (button) findviewbyid(r.id.calcpdty_dt); loader_pdty_calc = (button) findviewbyid(r.id.calcpdty_loader); fm_value_pdty_txt = (textview) findviewbyid(r.id.fm_pdty_value); dt_pdty = (edittext) findviewbyid(r.id.dtpdty_et); loader_pdty = (edittext) findviewbyid(r.id.loader_ct_et); vdtpdty=(float) 0.0; vloaderpdty=(float) 0.0; calc_fm_pdty.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub //if (dt_ct.gettext().tostring() <>""){ if ((dt_pdty.gettext().tostring()!=null) && (loader_pdty.gettext().tostring()!=null)) { fm_value_pdty = ((float) integer.parseint(dt_pdty.gettext().tostring()))/((float) integer.parseint(loader_pdty.gettext().tostring())); fm_value_pdty_txt.settext("fleet matching value " + fm_value_pdty); } else if ((dt_pdty.gettext().tostring()==null) || (loader_pdty.gettext().tostring()==null)) { alertdialog.builder dlgalert = new alertdialog.builder(getapplicationcontext()); dlgalert.setmessage("please input dt productivty , loader productivty"); dlgalert.settitle("data empty"); dlgalert.setpositivebutton("ok",null); dlgalert.setcancelable(true); dlgalert.create().show(); } } }); dt_pdty_calc.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { dt_pdty.vloaderpdty=vloaderpdty; dt_pdty.settext(""); loader_pdty.settext(""); intent pdty = new intent(main.this, dt_pdty.class); startactivity(pdty); dt_pdty.settext(float.tostring(vdtpdty)); loader_pdty.settext(float.tostring(vloaderpdty)); } }); loader_pdty_calc.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v2) { ld_pdty.vdtpdty=vdtpdty; dt_pdty.settext(""); loader_pdty.settext(""); intent pdty = new intent(main.this, ld_pdty.class); startactivity(pdty); dt_pdty.settext(float.tostring(vdtpdty)); loader_pdty.settext(float.tostring(vloaderpdty)); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
the code simple when try activate activity button first edit text emptied , activity start , after activity finish edit text has emptied fill calculated value activity. want make program has 2 edit text , 2 button. first edit text filled result first button , same other edit text , button. problem result first button when run second activity second button error. logcat because view of first edit text. updated post logcat.
08-20 19:52:47.924: d/androidruntime(237): shutting down vm 08-20 19:52:47.958: w/dalvikvm(237): threadid=3: thread exiting uncaught exception (group=0x4001b188) 08-20 19:52:47.958: e/androidruntime(237): uncaught handler: thread main exiting due uncaught exception 08-20 19:52:48.028: e/androidruntime(237): java.lang.nullpointerexception 08-20 19:52:48.028: e/androidruntime(237): @ com.example.fleetmatcher.main$2.onclick(main.java:66) 08-20 19:52:48.028: e/androidruntime(237): @ android.view.view.performclick(view.java:2364) 08-20 19:52:48.028: e/androidruntime(237): @ android.view.view.ontouchevent(view.java:4179) 08-20 19:52:48.028: e/androidruntime(237): @ android.widget.textview.ontouchevent(textview.java:6541) 08-20 19:52:48.028: e/androidruntime(237): @ android.view.view.dispatchtouchevent(view.java:3709) 08-20 19:52:48.028: e/androidruntime(237): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:884) 08-20 19:52:48.028: e/androidruntime(237): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:884) 08-20 19:52:48.028: e/androidruntime(237): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:884) 08-20 19:52:48.028: e/androidruntime(237): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:884) 08-20 19:52:48.028: e/androidruntime(237): @ com.android.internal.policy.impl.phonewindow$decorview.superdispatchtouchevent(phonewindow.java:1659) 08-20 19:52:48.028: e/androidruntime(237): @ com.android.internal.policy.impl.phonewindow.superdispatchtouchevent(phonewindow.java:1107) 08-20 19:52:48.028: e/androidruntime(237): @ android.app.activity.dispatchtouchevent(activity.java:2061) 08-20 19:52:48.028: e/androidruntime(237): @ com.android.internal.policy.impl.phonewindow$decorview.dispatchtouchevent(phonewindow.java:1643) 08-20 19:52:48.028: e/androidruntime(237): @ android.view.viewroot.handlemessage(viewroot.java:1691) 08-20 19:52:48.028: e/androidruntime(237): @ android.os.handler.dispatchmessage(handler.java:99) 08-20 19:52:48.028: e/androidruntime(237): @ android.os.looper.loop(looper.java:123) 08-20 19:52:48.028: e/androidruntime(237): @ android.app.activitythread.main(activitythread.java:4363) 08-20 19:52:48.028: e/androidruntime(237): @ java.lang.reflect.method.invokenative(native method) 08-20 19:52:48.028: e/androidruntime(237): @ java.lang.reflect.method.invoke(method.java:521) 08-20 19:52:48.028: e/androidruntime(237): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:860) 08-20 19:52:48.028: e/androidruntime(237): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:618) 08-20 19:52:48.028: e/androidruntime(237): @ dalvik.system.nativestart.main(native method) 08-20 19:52:48.201: i/dalvikvm(237): threadid=7: reacting signal 3 08-20 19:52:48.422: i/dalvikvm(237): wrote stack trace '/data/anr/traces.txt' 08-20 19:52:50.620: i/process(237): sending signal. pid: 237 sig: 9
will need logcat know exact problem. few observations:
- dont try update edittext after startactivity(pdty).
- you dont need clear edittext replace text, i.e dont need
edittext.settext("");
- if want clear edittext, there way:
edittext.gettext.clear();
hope useful.
Comments
Post a Comment