I am trying to retrieve a JSONObject
from database but I found out that the request don't even make it to the Server. I checked the Apache Access Log
to confirm this. The URL is valid and when I access it via a web browser, it return the expect JSONObject. The exception error show null
by the Volley library.
private void GetSchInfo(){
showDialog();
// making fresh volley request and getting json
JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.GET,
URL_SchInfo, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try{
spinnerClass.setVisibility(View.VISIBLE);
spinnerSch.setVisibility(View.VISIBLE);
spinnerDept.setVisibility(View.VISIBLE);
btnRegClass.setVisibility(View.VISIBLE);
txtClassMsg.setVisibility(View.VISIBLE);
btnRefresh.setVisibility(View.GONE);
JSONArray schools = response.getJSONArray("sch_info");
JSONArray departments = response.getJSONArray("dept_info");
for (int i = 0; i < schools.length(); i++){
JSONObject schObj = (JSONObject)schools.get(i);
SchInfo sch = new SchInfo(schObj.getString("school_id"), schObj.getString("school_name"));
schoolList.add(sch);
}
for (int j = 0; j < departments.length(); j++){
JSONObject deptObj = (JSONObject)departments.get(j);
DeptItem dept = new DeptItem(deptObj.getString("department_id"), deptObj.getString("department_name"));
deptList.add(dept);
}
//populate
//populateInfo();
}catch(JSONException e){
Log.e(TAG, "JSON Error: " + e.getMessage());
e.printStackTrace();
spinnerClass.setVisibility(View.GONE);
txtClassMsg.setVisibility(View.GONE);
spinnerSch.setVisibility(View.GONE);
spinnerDept.setVisibility(View.GONE);
btnRegClass.setVisibility(View.GONE);
btnRefresh.setVisibility(View.VISIBLE);
}
hideDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String body;
if (error.networkResponse.data !=null){
try {
body = new String(error.networkResponse.data, "UTF-8");
}catch (UnsupportedEncodingException e){
e.printStackTrace();
}
}
Log.e("Error: ", error.getCause() +">>" + error.getMessage());
Log.e(TAG, "JSON Error: " + error.getMessage() );
hideDialog();
spinnerClass.setVisibility(View.GONE);
spinnerSch.setVisibility(View.GONE);
spinnerDept.setVisibility(View.GONE);
btnRegClass.setVisibility(View.GONE);
txtClassMsg.setVisibility(View.GONE);
btnRefresh.setVisibility(View.VISIBLE);
}
});
// Adding request to volley request queue
AppController.getInstance().addToRequestQueue(jsonReq);
}
How do I solve this?
Note
The server is on my local machine, I connect via hotspot with something like http://192.164.***.***
.