0

I'm trying to acces my strings.xml from within the java code, but for some reason I can only acces some default android strings. This is what I do:

private static Context context;
context = getApplicationContext();

context.getString(R.string.somthing);

The R.string contains some strings but not what I have in strings.xml.

2
  • 3
    You are probably inporting the wrong 'R' class. Import the generated 'R' class located in /gen/ and not the 'android.R' class. Commented Jun 12, 2012 at 7:20
  • by the soud of it akalucas is right. This is a common mistake made by rookie android coders (including myself). Commented Jun 12, 2012 at 7:28

3 Answers 3

1

Did you import android.R or your generated R file ?

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

Comments

1

I think you imported android.R so just remove it and import your R.class like as

import your.package.name.R;

here your.package.name is your package name which you write in your Manifest.xml file.

1 Comment

if some one answered the same already that you are about to answer. prefer voting up rather posting same.
0

Use this code instead

Resources resources = context.getResources();
resources.getString(R.string.something)

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.