Volley请求始终获得Error Listener

时间:2015-01-08 08:17:04

标签: java android json android-volley

  JsonObjectRequest movieReq = new JsonObjectRequest(Request.Method.GET,url, null,
        new Response.Listener<JSONObject>() {
    @Override
    public void onResponse(JSONObject response) 
    {
        try {
            JSONArray images = response.getJSONArray("images");
            for(int i = 0; i<images.length(); i++)
            {
                try {
                    JSONObject obj =(JSONObject)images.get(i);

                    //JSONObject obj = images.getJSONObject(i);
                    Movie movie = new Movie();
                    movie.setTitle(obj.getString("itemid"));
                    movie.setThumbnailUrl(obj.getString("imagepath"));
                    movieList.add(movie);
                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
        } 
        catch (JSONException e) {


        }
        adapter.notifyDataSetChanged();
    };

        } 
        , new Response.ErrorListener(

                ) {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // TODO Auto-generated method stub
                        Toast.makeText(getApplicationContext(), "Error in Json parse", Toast.LENGTH_LONG).show();
                        hidePDialog();
                    }
        });

JSON部分:

{ 
"images": 
{ 
"imageid":"1",
"itemid":"item1",
"imagepath":"http:\/\/127.0.0.1\/resturant\/image\/chinese1.jpg"
},
{ 
"imageid":"2",
"itemid":"item2",
"imagepath":"http:\/\/127.0.0.1\/resturant\/image\/chinese2.jpg"
}
]
}

这里我想从图像JSON数组中检索itemid和imagepath标记。但我的JSON没有重新发送,它显示了错误监听器的祝酒词。请帮忙吗?我获得了互联网的许可,并检查了网址并且它正在运行。

1 个答案:

答案 0 :(得分:1)

请显示您呼叫的url的内容。如果您的URL包含127.0.0.1,则您正在调用android模拟器的本地主机(并且您的服务器不在模拟器上运行)。

要从模拟器调用PC的本地主机,您必须将127.0.0.1替换为10.0.2.2