Reputation: 47
hi I'm working in my android app. and suddenly today while I was working I got two errors 1- the "R can't be resolved as a variable" error. 2- and the "Couldn't resolve resource @string/app_name" erro, at the graphical view of .XML layouts.
I did lots of searching and lots of trial and error(clean, build, restart eclipse, restart laptop, and others but none could get me out of this trouble. I also noticed that My R.Java is gone I found while I do online searching that R.java could be gone"not auto generated" if there's error with XML or errors such as number 2 error.
last thing which I think might have caused the error is I added two elements in string.xml.. but anyway I have deleted them already.
so could any body help me how to jump this issue and continue with my development
Upvotes: 0
Views: 977
Reputation: 2045
Just import com.your.packagename.R
See my answer here Cannot find R.layout.activity_main
Upvotes: 0
Reputation: 113
In my experience this message is almost always something to do with an error in one of your XML files: could be string.xml, any of your layouts, styles etc.
My advice would be to open up each one of them individually and check through them. An error in the layouts (res/layout/..) should be easy enough to spot (don't forget to check your res/menu/.. also). An error in one of the value XML files (res/values/..) can be tricker to spot. As some of the others have mentioned, a simple error in these files can cause this: one of my most common ones is to have typed "sting" instead of "string" or something similar.
I have often found that even after fixing some of these it is neccessary to close everything down and start Eclipse again.
Upvotes: 0
Reputation: 243
Remove this line: import android.R note: R.java could be gone not auto generated unless you have no error in project. now you count replace @string/app_name by "app name" and clean again. after find where have error
Upvotes: 1
Reputation: 242
Take a good look at you string.xml file. The error is almost 100% there . Have you forgotten to close some tag? Check that your @string/app_name is well defined too ..
Upvotes: 1
Reputation: 1085
At a guess I'd say that there is something wrong in your resource files which is stopping it from compiling them into the R file.
Upvotes: 2