I\'ve got an error:
R cannot be resolved to a variable
in line:
setContentView(R.layout.main);
but I can\'t r
Don't import Android.R;
instead,
import package.name.R;
where package.name
is your package name declared in the manifest.
Android.R
contains all the default layouts packaged with Android. Your custom layout will not be Android.R
, it will be in package.name.R;
On eclipse you have the "Problems" window. If you fix all the other problems in there other than R cannot be resolved, the "R" problem will be auto-fixed as R is not generated because most likely you have project related problems.
Hope this helps. If you don't manage to do it, put a print of what your Problems window is showing.
Problem is solved, but I don't know what has changed... I reinstalled Eclipse, SDK etc. and gen folder was empty as before, the same problem.
My supervisor told me to do it all again, and it worked (for now). I don't know what was the cause. I though I'd had tried everything, but it's working now so I'll never know. Thanks for your help guys!
Yeah, i got stuck on this for hours. My solution was to: delete all projects from workspace->re-import the desired project by going to file->import->Browse->selecting the project->and finally check the "add project to working sets box" then clicking finish. The .R errors i once had then disappeared. I hope this helps someone!
Try this:
setContentView(R.layout.main);
setContentView(R.layout.main);
This should resolve the problem hopefully.
Nothing mentioned above worked for me. However, I fixed it myself.
If you've any other files except activity_main.xml
/ main.xml
inside app_name/res/layout
remove it and try clean and build.
The unwanted files or (rather used later) files inside app_name/res/layout
would be *.out.xml
. Remove the same.