java - Alert dialog not functioning correctly. -
this code working on requires user press button after entering phone number text box. button made save number.
when run code want have present user alert dialog asking them enter number if pressed button no number present.
instead of getting alert dialog app crashes. number entered app works fine.
any advice on awesome - here code stack trace under that. -thank you!
b.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { //create if statement brings alert dialog if there no number entered field. switch (v.getid()) { case r.id.btnwidgetconfig: { if (shareddata == null) { alertdialog.builder alert = new alertdialog.builder(c); alert.settitle("no number entered"); alert.setmessage("please enter phone number using the text box"); alert.setcancelable(false); alert.setpositivebutton("okay", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { startactivityforresult( new intent( android.provider.settings.action_location_source_settings), 0); } }); } else { string stringdata = shareddata.gettext().tostring(); long l = long.parselong(stringdata); sharedpreferences.editor editor = prefs.edit(); prefs.edit().putlong(constants.key, l).commit(); toast.maketext(c, "your number has been saved!", toast.length_long).show(); svnum.settext("saved number: " + prefs.getlong(constants.key, 411)); break; } } } } });
////stack trace:
05-14 12:29:07.679: w/dalvikvm(30842): threadid=1: thread exiting uncaught exception (group=0x40018560) 05-14 12:29:07.679: e/androidruntime(30842): fatal exception: main 05-14 12:29:07.679: e/androidruntime(30842): java.lang.numberformatexception: 05-14 12:29:07.679: e/androidruntime(30842): @ java.lang.long.parselong(long.java:337) 05-14 12:29:07.679: e/androidruntime(30842): @ java.lang.long.parselong(long.java:311) 05-14 12:29:07.679: e/androidruntime(30842): @ example.save.phonenum.settings$1.onclick(wwsettings.java:106) 05-14 12:29:07.679: e/androidruntime(30842): @ android.view.view.performclick(view.java:2485) 05-14 12:29:07.679: e/androidruntime(30842): @ android.view.view$performclick.run(view.java:9080) 05-14 12:29:07.679: e/androidruntime(30842): @ android.os.handler.handlecallback(handler.java:587) 05-14 12:29:07.679: e/androidruntime(30842): @ android.os.handler.dispatchmessage(handler.java:92) 05-14 12:29:07.679: e/androidruntime(30842): @ android.os.looper.loop(looper.java:130) 05-14 12:29:07.679: e/androidruntime(30842): @ android.app.activitythread.main(activitythread.java:3683) 05-14 12:29:07.679: e/androidruntime(30842): @ java.lang.reflect.method.invokenative(native method) 05-14 12:29:07.679: e/androidruntime(30842): @ java.lang.reflect.method.invoke(method.java:507) 05-14 12:29:07.679: e/androidruntime(30842): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:864) 05-14 12:29:07.679: e/androidruntime(30842): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:622) 05-14 12:29:07.679: e/androidruntime(30842): @ dalvik.system.nativestart.main(native method) 05-14 12:29:15.569: w/iinputconnectionwrapper(30870): showstatusicon on inactive inputconnection
i'm guessing shareddata
textview
. still trying parse result when null, hence nfe. put in check run code if there valid number. checking if null
, textview
may not contents empty string
trying parse
change
if (shareddata == null)
to like
if (shareddata == null || shareddata.gettext().tostring().equals("")) { ...
i try text before line stringdata
variable check if empty. also, want put try/catch
around parsing code in case try enter non-digit , display message, unless you've done that
Comments
Post a Comment