java - Android Text input always give me NaN value -
i can not figure out why code output show nan
. there can me figure out did mistake?
package com.example.user.solar_calculator; import android.app.activity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.content.context; import android.content.intent; import android.widget.button; import android.view.view; import android.view.view.onclicklistener; import android.widget.edittext; import android.widget.toast; public class efficiency extends activity { button button; edittext efficiency; edittext vol; string e,v; double e1,wat,v1, ac_load_in_ampere_hour_calculation,dc; double load,load_vol,total_daily_load,lol; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_efficiency); initcontrols(); addlisteneronbutton(); } public void initcontrols() { efficiency=(edittext)findviewbyid(r.id.edittext1); vol=(edittext)findviewbyid(r.id.edittext2); button=(button)findviewbyid(r.id.button); button.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { try { e1=double.parsedouble(efficiency.gettext().tostring()); // make use of autoboxing. it's easier read. } catch (numberformatexception e) { e1=1; } try { v1=double.parsedouble(vol.gettext().tostring());// make use of autoboxing. it's easier read. } catch (numberformatexception e) { v1=1; } bundle extras = getintent().getextras(); if(extras !=null) { string value = extras.getstring("four"); load=double.parsedouble(value.tostring()); } wat=load_vol*(1+.1); ac_load_in_ampere_hour_calculation = (load)/( v1* (e1/100)); total_daily_load=ac_load_in_ampere_hour_calculation+dc; intent = new intent(efficiency.this, calculation.class); //create bundle bundle bundle = new bundle(); //add data bundle bundle.putstring("seven", string.valueof(ac_load_in_ampere_hour_calculation)); bundle.putstring("eight", string.valueof(total_daily_load)); bundle.putstring("nine", string.valueof(dc)); //add bundle intent i.putextras(bundle); //fire second activity startactivity(i); } }); } public void addlisteneronbutton() { final context context = this; button = (button) findviewbyid(r.id.button); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
i think line cause problem ac_load_in_ampere_hour_calculation = (load)/( v1* (e1/100));
because if v1 = 0 impossible.
Comments
Post a Comment