Facing calculator app error in android -
friends searched lot didnt answer of question. trying make android calculator. simple 1 , single module of bigger app...
in firstly need users enter 1st , 2nd sunber , select if add, sub, mul, divide or mod..then there textview in result displayed.
this code using :
java code:
package com.droidacid.apticalc; import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview; public class numsys extends activity{ edittext etnumber1; edittext etnumber2; button badd; button bsub; button bmul; button bdiv; button bmod; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.numsys); etnumber1 = (edittext) findviewbyid(r.id.number1); etnumber2 = (edittext) findviewbyid(r.id.number2); string number1 = etnumber1.gettext().tostring(); string number2 = etnumber2.gettext().tostring(); final double number1d = double.parsedouble(number1); final double number2d = double.parsedouble(number2); badd.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub double resultd = number1d + number2d; string result = "result :"+resultd; textview tvresult = (textview) findviewbyid(r.id.tvresult); tvresult.settext(result); } }); bsub.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub double resultd = number1d - number2d; string result = "result :"+resultd; textview tvresult = (textview) findviewbyid(r.id.tvresult); tvresult.settext(result); } }); bmul.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub double resultd = number1d * number2d; string result = "result :"+resultd; textview tvresult = (textview) findviewbyid(r.id.tvresult); tvresult.settext(result); } }); bdiv.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub double resultd = number1d / number2d; string result = "result :"+resultd; textview tvresult = (textview) findviewbyid(r.id.tvresult); tvresult.settext(result); } }); bmod.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub double resultd = number1d % number2d; string result = "result :"+resultd; textview tvresult = (textview) findviewbyid(r.id.tvresult); tvresult.settext(result); } }); } }
this logcat error :
05-04 10:24:18.098: e/androidruntime(1321): java.lang.runtimeexception: unable start activity componentinfo{com.droidacid.apticalc/com.droidacid.apticalc.numsys}: java.lang.numberformatexception:
please dont rate post negative. trying learn , trying solve issue since last more 24 hours. tried posted on stack overflow.
thanks
this might problem:
string number1 = etnumber1.gettext().tostring(); string number2 = etnumber2.gettext().tostring(); final double number1d = double.parsedouble(number1); final double number2d = double.parsedouble(number2);
you're trying parse an, @ point, empty edittext double value. either that, or have default text in edittext you're trying parse.
this (probably) causes numberformatexception.
Comments
Post a Comment