Saturday, April 14, 2012

SOLVED: R.layout.main cannot be resolved to a variable

This is a misleading error message. A telltale symptom is your class file contains
import android.R; in your imports list. Remove this line, then look for the real cause of the error message.

More than likely, there is an error in a /res file preventing the project's 'R' file from being generated. If Eclipse can't find one, it will use Android's 'R' file. Check your /res folder for errors (red icons indicate errors). Finding the root cause might not be easy, but once you find and fix the error (and save it), a new 'R' file will be automatically generated.

When that happens, all should again be well with your code.

No comments:

Post a Comment