kylas
kylas

Reputation: 1455

Cannot cast 'com.android.volley.ServerError' to 'com.android.volley.NoConnectionError'

URL: http://androidtutorialpoint.com/api/volleyJsonObject

Code:

public void volleyJsonObjectRequest(String url) {

    String REQUEST_TAG = "JSONOBJ_TAG";

    JsonObjectRequest jsonObjectReq = new JsonObjectRequest(url, null,
    new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            Log.d("VOLLEY RESPONSE", response.toString());
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
            VolleyLog.d("VOLLEY ERROR", "Error: " + error.getMessage());
        }
    });

    // Adding JsonObject request to request queue
    AppSingleton.getInstance(getApplicationContext()).addToRequestQueue(jsonObjectReq, REQUEST_TAG);
}

I am trying to log the volley respone but I am getting the following error instead:

Cannot cast 'com.android.volley.ServerError' to 'com.android.volley.NoConnectionError'

I have checked the URL in the POSTMAN and it works fine. Is there something I am missing in my code? Been trying to debug but couldn't find the root cause.

Upvotes: 1

Views: 112

Answers (1)

kylas
kylas

Reputation: 1455

Found the solution:

Replace http with https

Upvotes: 1

Related Questions