【发布时间】:2017-11-16 19:02:30
【问题描述】:
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 in 微调器
public void GetAllData() {
JsonObjectRequest request=new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
ArrayList<CityList>mylist=new ArrayList<CityList>();
JSONArray array=response.getJSONArray("data");
for(int index=0;index<array.length();index++)
{
JSONObject object=array.getJSONObject(index);
mylist.add(new CityList(object.getInt("id"),object.getString("name")));
}
CityAdapter cityAdapter=new CityAdapter(MainActivity.this,R.layout.custome_spinner,R.id.humanmed,mylist);
ServiceName.setAdapter(cityAdapter);
} catch (JSONException e) {
Toast.makeText(MainActivity.this, "bad", Toast.LENGTH_SHORT).show(); }
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "sad", Toast.LENGTH_SHORT).show();
}
});
【问题讨论】: