android - Force down error in a calculation app(use if/if else) -
i have created app user places numbers editexts , app making calcs , displays number..i have 7 lines editexts .but 7th editext optional user fill it(i added checkbox , if user select editext visible,else invisible..).i have strange problem code , have help..
firstly code:
apostoli.setonclicklistener(new onclicklistener() { private alertdialog show; public void onclick(view arg0) { if ((vprosvasis.gettext().tostring() == " ") || (vprosvasis.gettext().length() == 0) || (vprosvasis2.gettext().tostring() == " ") || (vprosvasis2.gettext().length() == 0) || (vprosvasis3.gettext().tostring() == " ") || (vprosvasis3.gettext().length() == 0) || (vprosvasis4.gettext().tostring() == " ") || (vprosvasis4.gettext().length() == 0) || (vprosvasis5.gettext().tostring() == " ") || (vprosvasis5.gettext().length() == 0) || (vprosvasis6.gettext().tostring() == " ") || (vprosvasis6.gettext().length() == 0) ) { show = new alertdialog.builder(mcontext).settitle("error") .setmessage("symplirwste olous tous vathmous prosvasis") .setpositivebutton("ok", null).show(); } else if (((vprosvasis7.gettext().tostring() != " ") || (vprosvasis7.gettext().length() != 0))) { float genikosvathmos = (float) (( new float(vprosvasis.gettext().tostring()) + new float(vprosvasis7.gettext().tostring()) + new float(vprosvasis2.gettext().tostring()) + new float(vprosvasis3.gettext().tostring()) + new float(vprosvasis4.gettext().tostring()) + new float(vprosvasis5.gettext().tostring()) + new float( vprosvasis6.gettext().tostring())) / 7); float vprosvasisfloat = float.parsefloat(vprosvasis.gettext().tostring()); float vprosvasisfloat2 = float.parsefloat(vprosvasis2.gettext().tostring()); float vprosvasisfloat7 = float.parsefloat(vprosvasis7.gettext().tostring()); float vprosvasisfloat5 = float.parsefloat(vprosvasis5.gettext().tostring()); moria = (float) (((new float((genikosvathmos * 8)+ (vprosvasisfloat * 1.3)+ (vprosvasisfloat2 * 0.7)) * 100))); moria2 = (float) (((new float((genikosvathmos * 8)+ (vprosvasisfloat7 * 1.3)+ (vprosvasisfloat5 * 0.7)) * 100))); // toast.maketext(thetiki.this, "genikos vathmos"+moria , // toast.length_short).show(); // 1o pedio show = new alertdialog.builder(mcontext).settitle("moria") .setmessage( "1o pedio: " + moria + "\n2o pedio: " + moria + "\n3o pedio: " + moria + "\n4o pedio: " + moria + "\n5o pedio: "+moria2) .setpositivebutton("ok", null).show(); } else if ((vprosvasis.gettext().tostring()!= " ") || (vprosvasis.gettext().length() != 0) || (vprosvasis2.gettext().tostring() != " ") || (vprosvasis2.gettext().length() != 0) || (vprosvasis3.gettext().tostring() != " ") || (vprosvasis3.gettext().length() != 0) || (vprosvasis4.gettext().tostring() != " ") || (vprosvasis4.gettext().length() != 0) || (vprosvasis5.gettext().tostring() != " ") || (vprosvasis5.gettext().length() != 0) || (vprosvasis6.gettext().tostring() != " ") || (vprosvasis6.gettext().length() != 0) &&((vprosvasis7.gettext().tostring()== " ") || (vprosvasis7.gettext().length() == 0)) ) { float genikosvathmos = (float) ((new float(vprosvasis .gettext().tostring()) + new float(vprosvasis2.gettext().tostring()) + new float(vprosvasis3.gettext().tostring()) + new float(vprosvasis4.gettext().tostring()) + new float(vprosvasis5.gettext().tostring()) + new float( vprosvasis6.gettext().tostring())) / 6); float vprosvasisfloat = float.parsefloat(vprosvasis.gettext().tostring()); float vprosvasisfloat2 = float.parsefloat(vprosvasis2.gettext().tostring()); moria=(float) (((new float ((genikosvathmos*8)+(vprosvasisfloat * 1.3)+(vprosvasisfloat2 * 0.7))*100))); // toast.maketext(thetiki.this, "genikos vathmos"+moria , toast.length_short).show(); show = new alertdialog.builder(mcontext).settitle("moria") .setmessage("1o pedio: "+moria+"\n2o pedio: "+moria+"\n3o pedio: "+moria+"\n4o pedio: "+moria+"\n5o pedio: -") .setpositivebutton("ok", null).show(); } } });
vprosvasis,vprosvasis2
..etc number edittext.i have used 3 if/else.the first checks if 6 first editexts empty , if no there alert.the second check if vprosvasis7
not empty , make calculation.and finally,the third 1 want check if vprosvasis7
used , make new calc..this not working..specifically,the first if working,the second works two,but if havent filled 7th editext,the 3rd if stacks , forces down app..
your helpfull..
edit
logcat when 7th editext empty , press btn 'apostoli'
02-23 23:51:27.234: error/androidruntime(5739): fatal exception: main 02-23 23:51:27.234: error/androidruntime(5739): java.lang.numberformatexception: 02-23 23:51:27.234: error/androidruntime(5739): @ org.apache.harmony.luni.util.floatingpointparser.parsefloat(floatingpointparser.java:305) 02-23 23:51:27.234: error/androidruntime(5739): @ java.lang.float.parsefloat(float.java:291) 02-23 23:51:27.234: error/androidruntime(5739): @ java.lang.float.<init>(float.java:111) 02-23 23:51:27.234: error/androidruntime(5739): @ kostas.menu.moria.thetiki$8.onclick(thetiki.java:396) 02-23 23:51:27.234: error/androidruntime(5739): @ android.view.view.performclick(view.java:2461) 02-23 23:51:27.234: error/androidruntime(5739): @ android.view.view$performclick.run(view.java:8888) 02-23 23:51:27.234: error/androidruntime(5739): @ android.os.handler.handlecallback(handler.java:587) 02-23 23:51:27.234: error/androidruntime(5739): @ android.os.handler.dispatchmessage(handler.java:92) 02-23 23:51:27.234: error/androidruntime(5739): @ android.os.looper.loop(looper.java:123) 02-23 23:51:27.234: error/androidruntime(5739): @ android.app.activitythread.main(activitythread.java:4627) 02-23 23:51:27.234: error/androidruntime(5739): @ java.lang.reflect.method.invokenative(native method) 02-23 23:51:27.234: error/androidruntime(5739): @ java.lang.reflect.method.invoke(method.java:521) 02-23 23:51:27.234: error/androidruntime(5739): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:858) 02-23 23:51:27.234: error/androidruntime(5739): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616) 02-23 23:51:27.234: error/androidruntime(5739): @ dalvik.system.nativestart.main(native method) 02-23 23:51:27.249: warn/activitymanager(2944): force finishing activity kostas.menu.moria/.thetiki 02-23 23:51:27.300: info/(2944): dumpmesg > "/data/log/dumpstate_app_error.log"
float vprosvasisfloat7 = float.parsefloat(vprosvasis7.gettext().tostring());
so, when edittext empty, you're calling float.parsefloat(""); empty string not valid float, float class throws exception.
check empty string before parsing.
if (vprosvasis7.gettext().tostring.equals("")) { float vprosvasisfloat7 = float.parsefloat(vprosvasis7.gettext().tostring()); }
Comments
Post a Comment