Reputation: 177
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
Upvotes: 1
Views: 2081
Reputation: 13474
You must set "string"
and not "strings"
as the second parameter.
String myArt = getString(getResources().getIdentifier(imageString, "string", getPackageName()));
Upvotes: 2
Reputation: 22592
Based on your comments, you need this:
String myArt = getString(getResources().getIdentifier("report_TJ_btn " + e.getString("artID"), "strings", getPackageName()));
Upvotes: 1