JsonObjectRequest 在 android 中总是返回 onErrorResponse
public void clickFind(final View view) {
EditText find = (EditText) findViewById((R.id.editText));
// String
web = "http://api.tvmaze.com/search/shows?q=" + find.getText();
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, web, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("value");
lv = (ListView) findViewById(R.id.listView);
RowItem ri = null;
URL newurl = null;
for (int i = 0; i < jsonArray.length(); i++) {
try {
newurl = new URL(jsonArray.getJSONObject(i).getString("image"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
ri = new RowItem(newurl,jsonArray.getJSONObject(i).getString("name")
,jsonArray.getJSONObject(i).getString("summary"));
}
CustomListViewAdapter adapter = new CustomListViewAdapter(view.getContext(),R.layout.cf, ri);
lv.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Context context = view.getContext();
Toast.makeText(context, "error to upload "+web, Toast.LENGTH_SHORT).show();
}
});
queue.add(request);
} }
例如: http ://api.tvmaze.com/search/shows?q=bob
这带来了回复,但运行 of6 android 手机总是出错 有人知道代码有什么问题吗?