请帮助我修复此代码,我是一名新程序员,并开始在android studio上学习Java。这里的代码。我已经修复了它,但没有进行编译。问题太多了
private void request()
{
Log.d("VOLLE------","MAUKKKK");
JsonArrayRequest requestItem = new JsonArrayRequest(Request.Method.POST, url,null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
for (int i = 0; i < response.length(); i++) {
try {
JSONObject data = response.getJSONObject(i);
OurData item = new OurData();
item.setId(data.getString("idperawatan"));
item.setmText1(data.getString("nama"));
item.setmText2(data.getString("alamat"));
item.setmImageResource(data.getString("image"));
mList.add(item);
} catch (JSONException e) {
e.printStackTrace();
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
mAdapter.notifyDataSetChanged();
}
});
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(requestItem);
}
答案 0 :(得分:2)
好像在抱怨JsonArrayRequest()
中的参数不匹配。尝试删除POST方法和JSONArray参数,并将url字符串作为第一个参数传递:
private void request() {
Log.d("VOLLE------","MAUKKKK");
JsonArrayRequest requestItem = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
for (int i = 0; i < response.length(); i++) {
try {
JSONObject data = response.getJSONObject(i);
OurData item = new OurData();
item.setId(data.getString("idperawatan"));
item.setmText1(data.getString("nama"));
item.setmText2(data.getString("alamat"));
item.setmImageResource(data.getString("image"));
mList.add(item);
} catch (JSONException e) {
e.printStackTrace();
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
mAdapter.notifyDataSetChanged();
}
});
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(requestItem);
}