Error: incorrect_toast cannot be resolved


#1

Hi, I have an error once I created the Toast event listeners in the onCreate() method. it says:[quote] incorrect_toast cannot be resolved or is not a field[/quote].

Yet I checked in my strings.xml file and I have made strings for both of these variables there:

<string name="correct_toast">Correct!</string> <string name="incorrect_toast">Incorrect!</string>

Here is my QuizActivity.java file (most of it):

[code]package com.bignerdranch.android.geoquiz;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class QuizActivity extends Activity {

private Button mTrueButton;
private Button mFalseButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quiz);
    
    mTrueButton = (Button)findViewById(R.id.true_button);
    mTrueButton.setOnClickListener(new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			Toast.makeText(QuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();
		}
	});
    
    mFalseButton = (Button)findViewById(R.id.false_button);
    mFalseButton.setOnClickListener(new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			Toast.makeText(QuizActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT).show();
			
		}
	});
}[/code]

The errors are on 2 lines, where you see [quote]R.string.incorrect_toast[/quote] and [quote]R.string.correct_toast[/quote].

Why are these errors here? Can’t figure it out.

Thanks.


#2

Hi Nonimizu
I also had this issue yesterday and could not see a typo. In the end I found that the auto-generated file had not generated the lines for the two toast items. I closed the windows and open them again and it appeared to refresh and add the lines to the file. I am not in front of the code to be able to be more precise, but hope my explanation gives you some ideas. It seemed like there was a delay in update the file via Eclipse.

  • Max.

#3

Thanks Max! The more I use Eclipse, the more I see many software errors happen here and there. So good call. I think this error went away mysteriously, so probably like you described it! Sometimes saving or closing/reopening does some good. :unamused: