java - How to display the computed value in the Textview -
i wondering why pieces of code within public void onclick(view v) method not working. when click button calculate, pop box displaying , notifies me: application has stopped unexpectedly.. there no such error when removed pieces of code (inside method public void onclick(view v) means problem on code , not on manifest file. give thanks answering question , godbless :d
import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.*; public class form2 extends activity { string str1=""; string str2=""; string str3=""; string str4=""; string str5=""; string str6=""; string totalstring = null; double num1=0; double num2=0; double num3=0; double num4=0; double num5=0; double num6=0; double a=0; double b=0; double c=0; double total=0; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.form2); final textview nametv=(textview)findviewbyid(r.id.nametv); nametv.settext(getintent().getextras().getstring("namekey")); final textview subjtv=(textview)findviewbyid(r.id.subjtv); subjtv.settext(getintent().getextras().getstring("subjectkey")); final textview tv1=(textview)findviewbyid(r.id.tv1); final edittext firstetxt=(edittext)findviewbyid(r.id.et1); final edittext firstaetxt=(edittext)findviewbyid(r.id.et1a); final edittext secondetxt=(edittext)findviewbyid(r.id.et2); final edittext secondaetxt=(edittext)findviewbyid(r.id.et2a); final edittext thirdetxt=(edittext)findviewbyid(r.id.et3); final edittext thirdaetxt=(edittext)findviewbyid(r.id.et3a); imagebutton calcubutt=(imagebutton)findviewbyid(r.id.calcb); calcubutt.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { if(v.getid()==r.id.calcb) { str1=firstetxt.gettext().tostring(); num1=double.parsedouble(str1); str2=firstaetxt.gettext().tostring(); num2=double.parsedouble(str2); str3=secondetxt.gettext().tostring(); num3=double.parsedouble(str3); str4=secondaetxt.gettext().tostring(); num4=double.parsedouble(str4); str5=thirdetxt.gettext().tostring(); num5=double.parsedouble(str5); str6=thirdaetxt.gettext().tostring(); num6=double.parsedouble(str6); a=num1*num2; b=num3*num4; c=num5*num6; total=a+b+c; totalstring = double.tostring(total); tv1.settext(totalstring); }} }); } }
and xml code:
<?xml version="1.0" encoding="utf-8"?> <absolutelayout android:id="@+id/widget0" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/bg" > <textview android:id="@+id/widget33" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="enter scores have and" android:textsize="16sp" android:typeface="sans" android:textcolor="#000000" android:layout_x="10px" android:layout_y="42px" > </textview> <edittext android:id="@+id/et3" android:layout_width="57px" android:layout_height="35px" android:textsize="18sp" android:layout_x="10px" android:layout_y="232px" > </edittext> <edittext android:id="@+id/et1" android:layout_width="56px" android:layout_height="33px" android:textsize="13sp" android:layout_x="10px" android:layout_y="152px" > </edittext> <edittext android:id="@+id/et2" android:layout_width="55px" android:layout_height="34px" android:textsize="18sp" android:layout_x="10px" android:layout_y="192px" > </edittext> <edittext android:id="@+id/et3a" android:layout_width="57px" android:layout_height="34px" android:textsize="18sp" android:layout_x="70px" android:layout_y="232px" > </edittext> <edittext android:id="@+id/et2a" android:layout_width="57px" android:layout_height="32px" android:textsize="18sp" android:layout_x="70px" android:layout_y="192px" > </edittext> <edittext android:id="@+id/et1a" android:layout_width="57px" android:layout_height="35px" android:textsize="13sp" android:layout_x="70px" android:layout_y="152px" > </edittext> <textview android:id="@+id/tv1" android:layout_width="122px" android:layout_height="wrap_content" android:text="textview" android:textcolor="#ff000000" android:layout_x="120px" android:layout_y="162px" > </textview> <textview android:id="@+id/tv2" android:layout_width="128px" android:layout_height="wrap_content" android:text="textview" android:textcolor="#ff000000" android:layout_x="120px" android:layout_y="212px" > </textview> <edittext android:id="@+id/ete" android:layout_width="98px" android:layout_height="37px" android:layout_x="120px" android:layout_y="242px" > </edittext> <textview android:layout_height="wrap_content" android:textcolor="#000000" android:textsize="18sp" android:text="subjecttextview" android:id="@+id/nametv" android:layout_width="wrap_content" android:textstyle="bold" android:layout_x="13dip" android:layout_y="122dip"> </textview> <textview android:layout_height="wrap_content" android:textcolor="#000000" android:textsize="16sp" android:text="the equivalent percentage of in subject" android:typeface="sans" android:id="@+id/widget34" android:layout_width="wrap_content" android:layout_x="13dip" android:layout_y="74dip"> </textview> <textview android:layout_height="wrap_content" android:textcolor="#000000" android:textsize="18sp" android:text="nametextview" android:typeface="sans" android:id="@+id/subjtv" android:layout_width="144px" android:textstyle="bold" android:layout_x="48dip" android:layout_y="32dip"> </textview> <textview android:layout_height="wrap_content" android:textcolor="#000000" android:textsize="16sp" android:text="hi" android:typeface="sans" android:id="@+id/widget30" android:layout_width="wrap_content" android:layout_x="22dip" android:layout_y="34dip"> </textview> <imagebutton android:id="@+id/calcb" android:layout_height="36px" android:layout_width="100px" android:src="@drawable/calc" android:layout_x="122dip" android:layout_y="329dip"> </imagebutton> </absolutelayout>
without seeing total code, reason 1 of following:
yourdouble.parsedouble(strx)
calls can throw numberformatexception
- if string not contain parseable double. meaning need sure contain valid value. one of views null, ie has not been initialized phone call such secondetxt = (edittext) findviewbyid(r.id.yourid);
my guess 1 of edittext
views empty, causing above exception.
java android xml textview
No comments:
Post a Comment