1

I'm getting an error like exception org.json.JSONexception is never thrown in corresponding try block.
Whenever I try to remove the try catch block, the entire jsonobjectrequest() function is getting thet error.
When I try to remove the jsonexception to exception it also giving me errors.

private void getdata() {
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(  Request.Method.GET, url, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                           // Toast.makeText(Live.this, response.toString(),Toast.LENGTH_SHORT).show();


                            tv.setText("Response => "+response.toString());


                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                });
        //add request to queue
        queue.add(jsonObjectRequest);

    }
SHINTO JOSEPH
  • 377
  • 4
  • 17
  • what if you wrap the whole `JsonObjectRequest` in a try and catch? – Apostrofix May 23 '16 at 07:33
  • @Apostrofix whenever i remove the try catch the entire function become error – SHINTO JOSEPH May 23 '16 at 07:40
  • Well JsonObjectRequest expects a JSON reply, it will receive the data, parse it into a JSONObject and call the onResponse function. You will be too late by then. So make sure the JSON is correct. – RvdK May 23 '16 at 08:30

0 Answers0