1

I'm trying to call a string from my strings.xml, this one:

<string name="before">I have read and understood the</string>

I use this line to call the string:

String append1 = getResources().getString(R.string.before);

I get "before cannot be resolved or is not a field", but if I use another string from the same file it works just fine. You know if you type "...(R.string." you get a list of available strings to choose from, and some of my strings aren't showing in that list. How come?

2
  • Try to clean your application from Project->clean. Commented Aug 24, 2013 at 5:53
  • refresh/clean may help u Commented Aug 24, 2013 at 6:04

3 Answers 3

5

Sometimes when you declare the strings in the strings.xml and then try to use those using R.string. immediately, eclipse is not able to generate its id in .R file which is auto generated and stored ids.... so whenever such things happens, you should always make sure that you save all the files and clean and build the project.

In almost all such cases, just save, clean and build will work prevented it is some special case.

All the best.

Sign up to request clarification or add additional context in comments.

Comments

0

I had the same problem.
Make sure you don't have any errors in your .xml files.
After fixing my errors in .xml resources or commenting them the id was instantly generated in R.java.

Comments

0

I had the same error but the moment that I saved the project worked. If you have no other errors in the xml file, a save should do the job.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.