排球请求响应无法正常工作error.getMessage()

时间:2017-03-24 06:34:36

标签: android request android-volley response

我正在开发我的应用程序,直到早上工作正常。我在我的应用中使用了凌空。突然它停止了工作。我无法向服务器发送请求并获得响应。它转到onErrorResponse方法。以下是我的代码段

 private void makeJsonArrayRequestCountry() {

        showpDialog();
        JsonArrayRequest req = new JsonArrayRequest( myorderlist_url,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        Log.d("ress", response.toString());
                        placeorderlists=new ArrayList<MyOrderModel>();;

                        if(response.length() > 0)
                        {
                            for (int i = 0; i < response.length(); i++) {
                                try {

                                    JSONObject obj = response.getJSONObject(i);

                                    MyOrderModel movie = new MyOrderModel();
                                    movie.setOrder_Id(obj.getString("orderID"));
                                    movie.setOrder_Name(obj.getString("packDesc"));
                                    movie.setOrder_Imgpath(obj.getString("packImagePath"));
                                    movie.setOrder_Img(obj.getString("packImageName"));
                                    movie.setOrder_date(obj.getString("orderDate"));
                                    movie.setOrder_Status(obj.getString("orderStatus"));
                                    movie.setCancel_Status(obj.getString("isCancelled"));

                                    placeorderlists.add(movie);


                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                                textcounter.setText("Total Order : "+placeorderlists.size());

                            }
                        }
                        else
                        {
                            AlertDialog.Builder builder = new AlertDialog.Builder(MyOrderListActivity.this);

                            builder.setMessage("You Have No Order");

                            String positiveText = getString(android.R.string.ok);
                            builder.setPositiveButton(positiveText,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            // positive button logic
                                            Intent intentc=new Intent(MyOrderListActivity.this,OrderActivity.class);
                                            startActivity(intentc);
                                        }
                                    });

                            String negativeText = getString(android.R.string.cancel);
                            builder.setNegativeButton(negativeText,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            // negative button logic
                                        }
                                    });

                            AlertDialog dialog = builder.create();
                            // display dialog
                            dialog.show();
                        }

                        // Parsing json


                        rcAdapter = new RecyclerViewAdapterMyorderlist(MyOrderListActivity.this,  placeorderlists);
                        rView.setAdapter(rcAdapter);
                        // notifying list adapter about data changes
                        // so that it renders the list view with updated data

                        hidepDialog();

                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d("ErrorVolley", "Error: " + error.getMessage());
                Toast.makeText(getApplicationContext(),
                        error.getMessage(), Toast.LENGTH_SHORT).show();
                hidepDialog();

            }
        });

        MyApplication.getInstance().addToReqQueue(req, "jreq");
    }

在我的logcat中显示空白消息并获取空白吐司

VolleyLog.d("ErrorVolley", "Error: " + error.getMessage());

1 个答案:

答案 0 :(得分:0)

使用以下代码段检查错误。

@Override
public void onErrorResponse(VolleyError error) {
    String body;
    //get status code here
    String statusCode = String.valueOf(error.networkResponse.statusCode));
    //get response body and parse with appropriate encoding
    if(error.networkResponse.data!=null) {
        try {
            body = new String(error.networkResponse.data,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    //do stuff with the body...
}