dieters
dieters

Reputation: 317

getString() from within java code

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.

Upvotes: 0

Views: 224

Answers (3)

Niranj Patel
Niranj Patel

Reputation: 33238

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.

Upvotes: 1

J. Maes
J. Maes

Reputation: 6892

Use this code instead

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

Upvotes: 0

MckyONeil
MckyONeil

Reputation: 94

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

Upvotes: 1

Related Questions