android - make calculation and toast it---error -
in app have 3 edittext user can place number.then.when user press button,i result of calculation editext.
this code,but app forces down..any please?
code:
float result = (float) ((((new double(input11.gettext().tostring()) + new double(input21.gettext().tostring()))/2)*0.3)+ (new double(input31.gettext().tostring())*0.7)); vprosvasis.settext(float.tostring(result));}
calculation:
float genikosvathmos = (float) ((new double(vprosvasis.gettext().tostring())+new double(vprosvasis7.gettext().tostring())+ new double(vprosvasis2.gettext().tostring())+new double(vprosvasis3.gettext().tostring()) +new double(vprosvasis4.gettext().tostring())+new double(vprosvasis5.gettext().tostring())+new double(vprosvasis6.gettext().tostring()))/7); float moria=(float) (((new float ((genikosvathmos*8)+("vprosvasis * 1.3")+("vprosvasis2 * 0,7"))*100))); toast.maketext(thetiki.this, "genikos vathmos"+moria , toast.length_short).show();
logcat:
02-23 13:57:50.255: warn/dalvikvm(20923): threadid=1: thread exiting uncaught exception (group=0x4001d7d0) 02-23 13:57:50.364: error/androidruntime(20923): fatal exception: main 02-23 13:57:50.364: error/androidruntime(20923): java.lang.numberformatexception: 02-23 13:57:50.364: error/androidruntime(20923): @ org.apache.harmony.luni.util.floatingpointparser.parsefltimpl(native method) 02-23 13:57:50.364: error/androidruntime(20923): @ org.apache.harmony.luni.util.floatingpointparser.parsefloat(floatingpointparser.java:321) 02-23 13:57:50.364: error/androidruntime(20923): @ java.lang.float.parsefloat(float.java:291) 02-23 13:57:50.364: error/androidruntime(20923): @ java.lang.float.<init>(float.java:111) 02-23 13:57:50.364: error/androidruntime(20923): @ kostas.menu.moria.thetiki$8.onclick(thetiki.java:372) 02-23 13:57:50.364: error/androidruntime(20923): @ android.view.view.performclick(view.java:2461) 02-23 13:57:50.364: error/androidruntime(20923): @ android.view.view$performclick.run(view.java:8888) 02-23 13:57:50.364: error/androidruntime(20923): @ android.os.handler.handlecallback(handler.java:587) 02-23 13:57:50.364: error/androidruntime(20923): @ android.os.handler.dispatchmessage(handler.java:92) 02-23 13:57:50.364: error/androidruntime(20923): @ android.os.looper.loop(looper.java:123) 02-23 13:57:50.364: error/androidruntime(20923): @ android.app.activitythread.main(activitythread.java:4627) 02-23 13:57:50.364: error/androidruntime(20923): @ java.lang.reflect.method.invokenative(native method) 02-23 13:57:50.364: error/androidruntime(20923): @ java.lang.reflect.method.invoke(method.java:521) 02-23 13:57:50.364: error/androidruntime(20923): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:858) 02-23 13:57:50.364: error/androidruntime(20923): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616) 02-23 13:57:50.364: error/androidruntime(20923): @ dalvik.system.nativestart.main(native method) 02-23 13:57:50.399: warn/activitymanager(2944): force finishing activity kostas.menu.moria/.thetiki
you're getting numberformatexception
. because float contains strings , can't parsed, here: new float ((genikosvathmos*8)+("vprosvasis * 1.3")+("vprosvasis2 * 0,7"))*100))
simply rid of ""
edit:
furthermore, vprosvasis
etc, edittexts or other kind of input must convert values in proper way to able calculations them. 1 possibility is:
float vprosvasisfloat = float.parsefloat(vprosvasis.gettext().tostring());
then can perform calculations using vprosvasisfloat
instead of vprosvasis
Comments
Post a Comment