java - How to convert double data in string to set on a textview on android studio -


i doing simple calculator, code:

public void calculate(view view){      edittext txt11 = (edittext)findviewbyid(r.id.txt1);     edittext txt22 = (edittext)findviewbyid(r.id.text2);     textview result = (textview)findviewbyid(r.id.resultado);      button btn = (button)findviewbyid(r.id.button);      double num1 = double.parsedouble(txt11.gettext().tostring());     double num2 = double.parsedouble(txt22.gettext().tostring());      double resultado = num1+num2;      result.settext(string.valueof(resultado));  } 

it doesn't show code error, when button clicked, error comes:

java.lang.nullpointerexception: attempt invoke virtual method 'android.text.editable android.widget.edittext.gettext()'

what going wrong?

from code , stacktrace, clear 1 of edittext's null.

so make sure using right id's , inflating right layouts.

also, code, there seems typo.

r.id.txt1 , r.id.text2

usually people follow coding standards in own style, these 2 id's doesn't match style.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -