I am trying to populate an adapter with information from my jsonArray. I have seen this done in many examples but I am getting an error that “The method getJSONObject(String) in the type JSONObject is not applicable for the arguments (int)”
Here’s the code…
// jsonArray declared and filled with information
int length = jsonArray.length();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
for (int i = 0; i < length; i++)
{
String obj = jsonArray.getJSONObject(i).getString("NAME");
adapter.add(obj);
}
As you can see in the documentation, the prototype of the function is not
getJSONObject(int)butgetJSONObject(java.lang.String), so you can’t use this function with your iI think you can use the
keys()function to get an Iterator with string name.