Search code examples
androidgetresourcegetstring

android: getResources().getIdentifier NotFound Exception


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


Solution

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

    String myArt = getString(getResources().getIdentifier(imageString, "string", getPackageName()));