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

有帮助吗?

解决方案

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

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

其他提示

Use String report_TJ_btn = "";

Based on your comments, you need this:

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top