Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, string resource not found

I'm working on an App, and I am getting weired errors. I put in some String resource in res/values/strings and saved it. Now If I want to access it in an Activity I get an error like this

07-13 11:16:20.050: ERROR/AndroidRuntime(5883): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f060006

And I can't figure out why. Resource looks like this:

<string name="dialog_download_text">please wait while downloading</string>

and I want to Access it like

public void onCreate(Bundle b){
    super.onCreate(b);
    String s = getResources().getString(R.string.dialog_download_text);
}

I also looked into R.java and found my Entry

public static final class string {
    public static final int dialog_download_cancel=0x7f060005;
    public static final int dialog_download_text=0x7f060007;
    public static final int dialog_download_title=0x7f060006;
}

I don't know what to do, because I never had a problem like this before. Please help me. Thanks all.

like image 923
Rafael T Avatar asked Jul 13 '11 09:07

Rafael T


People also ask

What is string resource in Android?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.

Where is the strings XML file located?

String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc. These views have a common attribute named text.

How to add special characters in string XML in Android?

How can I write character & in the strings. xml? In android studio, you can simply press Alt+Enter and it will convert for you.


2 Answers

Sometimes I get this error (once every 2 days), and it's because eclipse is not compiling the new code and it's deploying the old apk. I fix this by

  • doing a clean on eclipse (Project -> clean)
  • closing the emulator
  • restarting the adb server by running adb kill-server and adb start-server from the command line
like image 187
Augusto Avatar answered Sep 18 '22 19:09

Augusto


Most likely there's an extra import android.R; Then your string can't be found there. Otherwise, clean the project and rebuild it, try again, then report back.

like image 25
Ilya Saunkin Avatar answered Sep 20 '22 19:09

Ilya Saunkin