Volley get方法不起作用

时间:2016-04-22 11:41:06

标签: android get android-volley

我有问题。我试图在myapifilms上使用volley get方法获取电影名称,但无法使其工作。我在哪里犯错?

输出:排球错误

ShowUrl

   RequestQueue  requestQueue = Volley.newRequestQueue(getApplicationContext);



    ////




            String showUrl ="http://www.myapifilms.com/imdb/idIMDB?title=batman&token=mytoken&format=json&language=en-us&limit=10";




            JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, showUrl , new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    System.out.println(response);

                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    System.out.println(error.getMessage());
                    Toast.makeText(Welcome.this, "Volley Error", Toast.LENGTH_SHORT).show();

                }
            });

            requestQueue.add(jsObjRequest);

1 个答案:

答案 0 :(得分:0)

if(volleyError != null && volleyError.networkResponse != null) {
                VolleyError error = null;

                try {
                    error = new VolleyError(new String(volleyError.networkResponse.data));
                } catch (Exception var6) {
                    var6.printStackTrace();
                }

                try {
                    JSONObject e = null;
                    if(error != null) {
                        e = new JSONObject(error.getMessage());
                    }

                    String Error = e != null?e.getString("message"):"error";
                    System.out.println(Error);
                    Toast.makeText(Welcome.this, "Volley Error", Toast.LENGTH_SHORT).show();
                } catch (JSONException var5) {
                    var5.printStackTrace();
                }

            }