RapsFan1981
RapsFan1981

Reputation: 1197

Android - can't access strings with R.string

I am have trouble accessing a string I stored in strings.xml and don't know why.

res/values/strings.xml

    <?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="FileBrowser">FileBrowser</string>
    <string name="menu_settings">Settings</string>
    <string name="up_one_level">..</string>
    <string name="current_dir">.</string>
</resources>

Code

this.directoryEntries.add(getString(R.string.current_dir)); //current_dir is not being seen

Upvotes: 0

Views: 2634

Answers (2)

Jonathan Applebaum
Jonathan Applebaum

Reputation: 5986

Check that you did not add the following import by mistake:

import android.R

It happened to me several times this week.
Delete this line and everything will work as expected.

Upvotes: 2

Khantahr
Khantahr

Reputation: 8528

Usually this means you have an error in one of your XML files so it can't rebuild your resources. Look under the problems tab in Eclipse and you'll probably see an XML issue, could be in any of your XML files, not necessarily in strings.xml.

Upvotes: 1

Related Questions