java - Android application stopped working -
i making android calculator app class assignment. when press plusminus (+/-) key first , input numeric key; application stops working. when input numeric key , press plusminus button works fine.
else if (v.getid() == r.id.plusminus){ double newnumber = double.parsedouble(textdisplay.gettext().tostring()); total = newnumber * (-1); textdisplay.settext(total.tostring()); }
when app crashes, errors in logcat. helpful if post along question , relevant code. however, here pretty sure parsing/error-checking problem
when press plusminus (+/-) key first , input numeric key; application stops working
when press key, aren't checking valid input trying parse empty text. need error-checking such try/catch check invalid input. like
else if (v.getid() == r.id.plusminus){ try { double newnumber = double.parsedouble(textdisplay.gettext().tostring()); total = newnumber * (-1); textdisplay.settext(total.tostring()); } catch (numberformatexception e) { // maybe show relevant message here toast or // let user know invalid input entered } }
Comments
Post a Comment