org.json.JSONException: End of input at character 1

705 views Asked by At

I am trying to post data to server using Volley.I got a JsonException.I have no idea about it.I check if length of "response" is greater than 0.Then I log the response, but the response is not being displayed.Has anyone encountered such a problem before?Does anyone know the solution to this problem?

Code:

    public void report()
    {
        final ProgressDialog pr
                =new ProgressDialog(Report.this);
        pr.setMessage("Sending your review..");
        pr.setIndeterminate(false);
        pr.getWindow().setGravity(Gravity.CENTER);
        pr.show();
        SharedPreferences sharedPreferences1=getApplicationContext().getSharedPreferences("prsnl_Id",Context.MODE_PRIVATE);

        if (sharedPreferences1.contains("prsnlid"))
        {
            uid=Integer.toString(sharedPreferences1.getInt("prsnlid",0));
        }

        RequestQueue requestQueue= Volley.newRequestQueue(Report.this);
        StringRequest stringRequest=new StringRequest(Request.Method.POST, BaseUrl.getInstance().getUrl()+"/xyz.php", new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                   if (response.length()>0){

                        Log.e("Response",response);
                        try {
                            JSONObject jsonObject=new JSONObject(response);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                  pr.cancel();
                    }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                pr.cancel();

            }
        })
        {
            @Override
            protected Map<String, String> getParams()
            {
                HashMap<String,String> hashMap=new HashMap<>();
                hashMap.put("report",report);
                Log.e("uid",uid);
                hashMap.put("uid",uid);

                if (amb){
                    hashMap.put("cat","ambulance");
                    hashMap.put("cat_id", AmbulanceDisplayData.getInstance().getId());
                }
                else if (bldng){
                    hashMap.put("cat","building");
                    hashMap.put("cat_id", BuildingDisplayData.getInstance().getId());
                }
                else if (dctr){
                    hashMap.put("cat","doctor");
                    hashMap.put("cat_id", DoctorDisplayData.getInstance().getId());
                }
                else if (evnt){
                    hashMap.put("cat","event");
                    hashMap.put("cat_id", EventDisplayData.getInstance().getId());
                }
                else if (hsptl){
                    hashMap.put("cat","hospital");
                    hashMap.put("cat_id", HospitalDisplayData.getInstance().getId());
                }
                else if (hse){
                    hashMap.put("cat","house");
                    hashMap.put("cat_id", HouseDisplayData.getInstance().getId());
                }
                else if (prsnl_job){
                    hashMap.put("cat","job");
                    hashMap.put("cat_id", PersonalJobsDisplayData.getInstance().getId());
                }
                else if (phr){
                    hashMap.put("cat","pharmacy");
                    hashMap.put("cat_id", PharmacyDisplayData.getInstance().getId());
                }
                else if (rnt_srvcs){
                    hashMap.put("cat","rent");
                    hashMap.put("cat_id", RentServicesDisplayData.getInstance().getId());
                }
                else if (sellbuy){
                    hashMap.put("cat","sell_buy");
                    hashMap.put("cat_id", SellBuyDisplayData.getInstance().getId());
                }
                else if (vhcle){
                    hashMap.put("cat","vehicle");
                    hashMap.put("cat_id", String.valueOf(TaxiDisplayData.getInstance().getId()));
                }

            return hashMap;
            }
        };

        int sockettimeout=500000;
        RetryPolicy retryPolicy=new DefaultRetryPolicy(sockettimeout,0,0);
        stringRequest.setRetryPolicy(retryPolicy);
        requestQueue.add(stringRequest);
    }

Exception:

09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err: org.json.JSONException: End of input at character 1 of 
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at org.json.JSONTokener.nextValue(JSONTokener.java:97)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:156)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:173)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at com.example.jobinsabu.ohxee.report.Report$2.onResponse(Report.java:115)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at com.example.jobinsabu.ohxee.report.Report$2.onResponse(Report.java:105)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at android.os.Looper.loop(Looper.java:135)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5910)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
09-04 17:57:53.297 30241-30241/com.example.jobinsabu.ohxee W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
09-04 17:57:53.407 30241-30241/com.example.jobinsabu.ohxee E/ViewRootImpl: sendUserActionEvent() mView == null
0

There are 0 answers