1

I get my Data via json. Put it in a Hashmap und list it in a ListView. That works fine!

Now I want something like this:

String myArt=report_TJ_+e.getString("artID");

That does not work in my combination. Here is my Code:

  try{
    //String text = getString(R.string.report_TJ);
    JSONArray  earthquakes = json.getJSONArray("uTraf");
    mylist.clear();
    String report_TJ_btn = null;
            for(int i=0;i<earthquakes.length();i++){                        
                HashMap<String, String> map = new HashMap<String, String>();    
                JSONObject e = earthquakes.getJSONObject(i);

                String imageString=report_TJ_btn+e.getString("artID");
                String myArt = getString(getResources().getIdentifier(imageString, "", getPackageName()));

                map.put("id",  String.valueOf(i));
                map.put("first", myArt + "Stau: " + e.getString("road") + ", " + e.getString("county"));
                map.put("second", e.getString("timestamp") + ", " + e.getString("suburb"));
                mylist.add(map);
            }       
  }

Error: E/AndroidRuntime(641): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0

sarahsdev
  • 177
  • 6
  • 22

3 Answers3

2

You must set "string" and not "strings" as the second parameter.

String myArt = getString(getResources().getIdentifier(imageString, "string", getPackageName()));
znat
  • 13,144
  • 17
  • 71
  • 106
1

Based on your comments, you need this:

String myArt = getString(getResources().getIdentifier("report_TJ_btn " + e.getString("artID"), "strings", getPackageName()));

Rawkode
  • 21,990
  • 5
  • 38
  • 45
  • sorry, again the same error. eclipse want that I do this String report_TJ_btn = null; is this correct? – sarahsdev Dec 05 '12 at 13:42
  • OK I have a: getString(R.string.report_TJ_btn1) and in the strings.xml different languages. the artID gives a Number: report_TJ_btn + artID = report_TJ_btn1 = getString(R.string.report_TJ_btn1) That is what I want – sarahsdev Dec 05 '12 at 13:49
1

Use String report_TJ_btn = "";

viks
  • 404
  • 2
  • 6
  • 14