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 Activ
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.
Checkout this thread, it fixed my problem. R cannot be resolved - Android error
There are two cases you may get this error
1.your strings.xml file is not referred correctly?
Ans:give the correct package name for R.java file as per you application?
2.if you kept correct string.xlm path you may get still error?
Ans:once clean and build the projector restart the eclipse or android studio.
Thanks krishh
I also met this problem and it is very wired at first. 1: I make sure I import the correct R into my class 2: I checked R.java in the gen folder and the resource id is there. 3: I cleaned my project and remove from my phone and relaunch it the exception still there.
Finally I found the reason: I just added my resource string into the strings.xml in language-specific folder(say values-zh) but missed it in the default strings.xml in the default values folder.
then it is solved.
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
adb kill-server
and adb start-server
from the command lineI am currently writing the "net.superlinux.tcltktutorials" you can find it on play store now. now in the application, I want to use the standard way of using locales instead of my way of doing locales. I had to add for Arabic /res/vlaues-ar and I have the default for English /res/values. The app is about ad based YouTube Playlist TCL/Tk programming language tutorials. now the playlist can be in Arabic and in English. What I noticed is that if you have in the default /res/values 36 entries and in /res/values-ar 35 entries for the same playlist, this will make the ResourceNotFound exception. All you have to do is add the missing entry as empty at the bottom of your list just to make it equal in numbers in English and Arabic, Even if the English playlist is less in numbers.
This was my method of adding to the playlist formed inside the list activity, and also a clever way of using the resources as xml built in data:
package net.superlinux.tcltktutorials;
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListOfVideos extends ListActivity {
List<String> model = new ArrayList<String>();
ArrayAdapter<String> adapter = null;
List<String> filename = new ArrayList<String>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
adapter = new ArrayAdapter<String> (this, R.layout.list_item, model);
load_playlist();
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String selected_youtube_video=filename.get(position);
try {Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"+selected_youtube_video));
startActivity(i);
}
catch(Exception e){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v="+selected_youtube_video+"&loop=1&autoplay=1")));
e.printStackTrace();
}
}
void load_playlist()
{
int display_id=0;
int file_id=0;
//loop forever until nothing has to be added to the ListView or stop if the list item
// to be added does not exist.
for (int i=0;;i++){
display_id=getResources().getIdentifier("display_"+i, "string", getPackageName());
if (display_id!=0 && getString(display_id).length()!=0)
adapter.add(getString(display_id));
else {
Log.e("string id not found or empty","R.string.display_"+i );
return;
}
file_id=getResources().getIdentifier("file_"+i, "string", getPackageName());
if (file_id!=0 && getString(file_id).length()!=0){
filename.add(getString(file_id));
}
else {
Log.e("string id not found or empty","R.string.file_"+i );
return;
}
}
}
}