Reputation: 2707
First, hi to all of you. :)
I am learning Android and I am making some basic math program(game). It gets two random numbers, random operator, and 30 secs to solve math problems as much as you can.
I get error when I try to get text from EditText(Numbers only) and parse it to int. I need it because I need to compare real result to user input result.
I compile it, but when i run it on emulator, i got this error on ddms.
http://www4.slikomat.com/11/0921/bg9-Captur.jpg
Code: http://pastebin.com/u1MnZP34
Upvotes: 0
Views: 169
Reputation: 46856
You've declared your EditText but you never set it to anything, thus it is null.
EditText et1;
You need to add a findViewById() call for your EditText inside your onCreate, like you've done for your TextViews. Something like this is what you need I think.
et1 = (EditText) findViewById(R.id.editText1);
You should also really really use descriptive names for your variables. Using names like textView1, textView2, editText1 etc... is going to make your code A LOT harder to debug. Consider naming them something to do with what they are used for
firstOperandTxt, secondOperandTxt, answerEdt etc..
Upvotes: 2
Reputation: 3928
You have not initialized your EditText et1, hence you see NullPointer Exception. You should have something like
et1 = (EditText)findViewbyId(R.id.youtextid);
Upvotes: 2