I looked throughout the previous code in the book and could not find any mention to the variables incorrect_toast and correct_toast.
So I used the shortcut tool
alt enter
to correct it
it added the following
public static int correct_toast;
public static int incorrect_toast;
to R.java
This fixed the issue, however when the program was run the same errors occurred again and the code from R.java that was generated from pressing alt enter was deleted and I was back at square one.
I’m not sure if those vars are missing from the book or not, however, Android Studio mis-lead you a bit with adding those variables. It’s attempting to guess how to help, but in this case it guessed wrong.
Here’s how to fix it.
Open the strings.xml file under resources\values in your project. Here’s what it will look like, though mine is a different project.
Now just add those two new strings:
<string name=“correct_toast”>Correct</string>
<string name=“incorrect_toast”>Incorrect</string>
After you make that change :
delete* those variables that Android studio added for you
rebuild
That should fix it. These are String resources that are supposed to be defined separately.
EDIT
*Actually I’m not sure if you’ll need to delete the vars because you shouldn’t really edit the R.java by hand. First, try just rebuilding after altering your strings.xml.
Hi guys I’m new to Java and was wondering as to how we can assign a string to the messageResId variable although its initialized as an integer ? Thanks in advance!