i am a beginner in the android, and i dont know what is the problem in my code ! and i need your help, this is my code: i am trying to do a calculator = - / * ..... and i re
Either check you have initialized the view or may be layout not has been attached to activity.
password = (EditText) findViewById(R.id.password);
or
setContentView(R.layour.login_screen);
You are initializing a local copy of variable theresult
in onCreate
:
TextView theresult = (TextView) findViewById(R.id.TheResult);
But in onClick
you are trying to access another instance of the variable theresult
which is declared outside onCreate
. This one has not been initialized yet. That's why giving its giving null when you are trying to do setText
.
To solve, replace the below line:
TextView theresult = (TextView) findViewById(R.id.TheResult);
with
theresult = (TextView) findViewById(R.id.TheResult);