android - java.lang.runtimeexception unable to start activity componentinfo -
i having error in code
java.lang.runtimeexception unable start activity componentinfo
package estimatewall.example.com.estimatewall; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview; public class mainactivity extends actionbaractivity { edittext inputtxt; edittext inputtxt1; textview settext; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); inputtxt = (edittext) findviewbyid(r.id.edittext); // store edittext in variable int val = integer.parseint(inputtxt.gettext().tostring()); inputtxt1 = (edittext) findviewbyid(r.id.edittext2); // store edittext in variable int val1 = integer.parseint(inputtxt1.gettext().tostring()); float block1,block2; final float sum; block1=(val*12)/7; block2=(val1*12)/10; sum=block1*block2; button button = (button) findviewbyid(r.id.button); button.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { // perform action on click try { textview textview = (textview) findviewbyid(r.id.textview3); textview.settext("" + sum); }catch (exception e) { e.printstacktrace(); } } }); } @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); } }
probably getting numberformatexception
because here:
int val = integer.parseint(inputtxt.gettext().tostring());
trying convert null
int
.
use inputtxt.gettext()
inside onclick
method of button on click listener values input user in edittext or set default values in xml both edittext's android:text="0"