java - Application Crashed when I tried to compare integers -
here codes
public void onclick(view v) { if (v == buttonone) { textview output = (textview)findviewbyid(r.id.output); output.append("1"); } else if (v == buttontwo) { textview output = (textview)findviewbyid(r.id.output); output.append("2"); } else if (v == buttonthree) { textview output = (textview)findviewbyid(r.id.output); output.append("3"); } else if (v == buttonfour) { textview output = (textview)findviewbyid(r.id.output); output.append("4"); } else if (v == buttonfive) { textview output = (textview)findviewbyid(r.id.output); output.append("5"); } else if (v == buttonsix) { textview output = (textview)findviewbyid(r.id.output); output.append("6"); } else if (v == buttonseven) { textview output = (textview)findviewbyid(r.id.output); output.append("7"); } else if (v == buttoneight) { textview output = (textview)findviewbyid(r.id.output); output.append("8"); } else if (v == buttonnine) { textview output = (textview)findviewbyid(r.id.output); output.append("9"); } else if (v == buttonzero) { textview output = (textview)findviewbyid(r.id.output); output.append("0"); } else if(v == buttonenter) { textview output = (textview)findviewbyid(r.id.output); temp = integer.parseint(output.gettext().tostring()); comparenumber(temp); output.settext(""); } }
i trying compare number using button. example, if press buttonone append 1 stack. works fine when enter pressed after 1 or more number clicked, application stops when left edittext without entering numbers , press buttonenter.
please help!
the problem @ line
temp = integer.parseint(output.gettext().tostring());
when try use parseint()
empty string. crash up. have @ variable output.
solution
you can apply condition before doing value retrieved edittext
adding line
if(edittext.gettext().length() != 0)
Comments
Post a Comment