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
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);