0

I'm getting the following error:

com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of

This is my code:

public void onResponse(JSONObject response) {
    dialog.dismiss();
    Log.d("response", response.toString());
    JSONArray jsonArray = null;
    try {

        jsonArray = response.getJSONArray("assignments");
        if(jsonArray.length()==0)
        {
            Toast.makeText(getApplicationContext(), "Assignments Not Found", Toast.LENGTH_LONG).show();
        }
        CardView cardView=(CardView)findViewById(R.id.list_item5);
        cardView.setVisibility(View.VISIBLE);
        assignmentModuleListList.clear();
        for (int i = 0; i < jsonArray.length(); i++) {
            AssignmentModule assignmentModule = new AssignmentModule();
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            assignmentModule.setAssignmentName(jsonObject1.getString("assignmentName"));
            assignmentModule.setDescription(jsonObject1.getString("description"));
            assignmentModule.setSubjectName(jsonObject1.getString("subjectName"));
            String date=jsonObject1.getString("startDate").substring(0,10);
            String date1=jsonObject1.getString("endDate").substring(0, 10);
            assignmentModule.setAssignDate(date+"\n"+"\t\t\t"+"to"+"\n"+date1);

            assignmentModuleListList.add(assignmentModule);
        }

        setdata(assignmentModuleListList);
        dialog.dismiss();

    } catch (JSONException e) {
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
    }
}, 
new Response.ErrorListener() {

    @Override
    public void onErrorResponse(VolleyError error) {
        dialog.dismiss();
        Log.d("error",error.toString());
        String timeout=error.toString();
        if(timeout.equalsIgnoreCase("com.android.volley.TimeoutError"))
        {
            Toast.makeText(getApplicationContext(), "Opp's Server Can't Load Please Try Again Latter", Toast.LENGTH_LONG).show();
        }

        NetworkResponse response = error.networkResponse;
        if(response != null && response.data != null){
            switch(response.statusCode){
                case 400:
                    Toast.makeText(getApplicationContext(), "400 Error", Toast.LENGTH_LONG).show();
                    break;
                case 404:
                    Toast.makeText(getApplicationContext(), "Assignments Not Found", Toast.LENGTH_LONG).show();
                    break;
                case 500:
                    Toast toast1 = Toast.makeText(getApplicationContext(), "Internal Server Error", Toast.LENGTH_SHORT);
                    TextView v1 = (TextView) toast1.getView().findViewById(android.R.id.message);
                    v1.setTextColor(Color.RED);
                    toast1.show();
                    break;
            }
            //Additional cases
        }
    }

This is what I'm expecting after parsing:

{
    "assignments":[
        {
            "assignmentName":"asignment1",
            "description":"first poam",
            "subjectName":"kannada",
            "startDate":"2016-01-22",
            "endDate":"2016-01-23"
        },
        {
            "assignmentName":"assigment3",
            "description":"thrid lesson",
            "subjectName":"kannada",
            "startDate":"2016-01-22",
            "endDate":"2016-01-23"
        }
    ]
}
Daniel
  • 2,355
  • 9
  • 23
  • 30
vishwa
  • 1
  • check for similar questions first .http://stackoverflow.com/questions/8202048/org-json-json-exception-end-of-input-at-character-0 http://stackoverflow.com/questions/14036847/org-json-jsonexception-end-of-input-at-character – Sunil Sunny Jun 24 '16 at 09:22
  • make sure that the api returns the desired json result from server.try calling the service in postman or restclient. – darwin Jun 24 '16 at 09:28
  • check GET/POST method mismatch in both php/android . also check your json response is correct or not – Sathish Kumar J Jun 24 '16 at 09:30
  • there may be error in the json format which your api is returing as a response.You can check online http://www.jsoneditoronline.org/ for the validity of your json response – Gyanendra Mani Jun 24 '16 at 09:30
  • No this Api is working on localhost correctly, but is showing error in server only – vishwa Jun 24 '16 at 09:41

0 Answers0