1

I send one ArrayList to my Laravel server, I have good response (200) and I received my list, but in my Android application the callback function of volley library OnResponse is never call.

    JsonArrayRequest stringRequest = new JsonArrayRequest(url, jsonRequest, 
                new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            Log.d(TAG, "dropTable");
            dabAcces.dropTable();
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (row > MAX_REGISTER_GPS_DATA) {
                Log.d(TAG, "deleteOldestRecord");
                dabAcces.deleteOldestRecord();
            }
        }

    });
    // Add the request to the RequestQueue.
    queue.add(stringRequest);
}

The function never enter to onResponse, can not display response.

This is my Android code with volley HTTP POST :

        JSONArray jsonRequest = new JSONArray();
        for(MyLocation myLocation : ListLocation){
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("serial", myLocation.serial);
                jsonObject.put("longitude", myLocation.longitude);
                jsonObject.put("latitude", myLocation.latitude);
                jsonObject.put("altitude", myLocation.altitude);
                jsonObject.put("accuracy", myLocation.accuracy);
                jsonObject.put("detect_at", myLocation.date);
                jsonRequest.put(jsonObject);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

            JsonArrayRequest stringRequest = new JsonArrayRequest(url, jsonRequest, 
                    new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                Log.d(TAG, "dropTable");
                Log.d(TAG, "response " + response );
                dabAcces.dropTable();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d(TAG, "onErrorResponse" + error);
                if (row > MAX_REGISTER_GPS_DATA) {
                    Log.d(TAG, "deleteOldestRecord");
                    dabAcces.deleteOldestRecord();
                }
            }

        });
        // Add the request to the RequestQueue.
        queue.add(stringRequest);
    }
}

This is my Laravel Controller code :

    public function store()
{


    foreach ($input as $values){


            $tracker = new Tracker;
            $tracker->serial = $values["serial"];
            $tracker->latitude  = $values["latitude"];
            $tracker->longitude = $values["longitude"];
            $tracker->altitude  = $values["altitude"];
            $tracker->accuracy  = $values["accuracy"];
            $tracker->detect_at = $values["detect_at"];
            $tracker->created_at = \Carbon\Carbon::now()->toDateTimeString();
            $tracker->updated_at = \Carbon\Carbon::now()->toDateTimeString();
            $tracker->save();

    }

}

This is my log in Laravel, array sending by android application.

 0 => 
  array (
    'detect_at' => '2015-08-14 06:14:11',
    'longitude' => '-1.74099',
    'latitude' => '48.0492',
    'accuracy' => '39.695',
    'serial' => '7447c0f2916a7159',
    'altitude' => '0',
  ),
  1 => 
  array (
    'detect_at' => '2015-08-14 06:14:15',
    'longitude' => '-1.74095',
    'latitude' => '48.0492',
    'accuracy' => '42.057',
    'serial' => '7447c0f2916a7159',
    'altitude' => '0',
  ),
  2 => 
  array (
    'detect_at' => '2015-08-14 06:14:17',
    'longitude' => '-1.74092',
    'latitude' => '48.0492',
    'accuracy' => '43.351',
    'serial' => '7447c0f2916a7159',
    'altitude' => '0',
  ),
  3 => 
  array (
    'detect_at' => '2015-08-14 06:18:59',
    'longitude' => '-1.74095',
    'latitude' => '48.0492',
    'accuracy' => '41.781',
    'serial' => '7447c0f2916a7159',
    'altitude' => '0',
  ),
  4 => 
  array (
    'detect_at' => '2015-08-14 06:19:01',
    'longitude' => '-1.74093',
    'latitude' => '48.0492',
    'accuracy' => '42.812',
    'serial' => '7447c0f2916a7159',
    'altitude' => '0',
  ),
  5 => 
  array (
    'detect_at' => '2015-08-14 06:19:03',
    'longitude' => '-1.74093',
    'latitude' => '48.0492',
    'accuracy' => '42.812',
    'serial' => '7447c0f2916a7159',
    'altitude' => '0',
  ),
  6 => 
  array (
    'detect_at' => '2015-08-14 06:19:05',
    'longitude' => '-1.74093',
    'latitude' => '48.0492',
    'accuracy' => '42.948',
    'serial' => '7447c0f2916a7159',
    'altitude' => '0',
  ),
  7 => 
  array (
    'detect_at' => '2015-08-14 06:20:19',
    'longitude' => '-1.74095',
    'latitude' => '48.0492',
    'accuracy' => '41.865',
    'serial' => '7447c0f2916a7159',
    'altitude' => '0',
  ),
durron597
  • 31,968
  • 17
  • 99
  • 158
Hydral
  • 101
  • 1
  • 1
  • 10
  • 2
    Log.d(TAG, "dropTable"); is not showed in the log cat ? – Moudiz Aug 14 '15 at 08:50
  • why can't you print your response Log.d(TAG, "response " +response ); ? – King of Masses Aug 14 '15 at 08:52
  • No My Log dropTable is never call !!! – Hydral Aug 14 '15 at 08:57
  • Are you sure you are receiving json response , also check this link {so]()http://stackoverflow.com/questions/21556444/volley-never-returns-volleyerror-or-explains-why-there-is-an-exception) it might hekp you ? @Hydral – Moudiz Aug 14 '15 at 09:01
  • You should log the `error` in `onErrorResponse` .Also make sure you have Internet permission. – justHooman Aug 14 '15 at 09:01
  • I have internet permission. If I not received json response onErrorResponse should to be call no ? – Hydral Aug 14 '15 at 09:09
  • Ok, I received OnErrorListener, I forget to put an message -_-. But why it's not OnResponse which is call , if I received http 200? – Hydral Aug 14 '15 at 09:13
  • Have you initialized your request queue? You need to initialize the queue in order to make requests. – Marta Tenés Aug 14 '15 at 09:16
  • Yeah RequestQueue queue = Volley.newRequestQueue(this); – Hydral Aug 14 '15 at 09:17
  • I have his error onErrorResponsecom.android.volley.ParseError: org.json.JSONException: Value – Hydral Aug 14 '15 at 09:20
  • can you post your json response here. May be you are sending wrong format of json array data from your api. Use this to see your response, Log.d(TAG, response.toString()); – Rubanraj Ravichandran Aug 14 '15 at 13:08
  • I think you should override `parseNetworkResponse` and `parseNetworkError`, then debug to know if your android client can receive reponse from the server or not. – BNK Aug 14 '15 at 14:12

0 Answers0