【问题标题】:VOLLEY / ANDROID : error response with JsonArrayRequestVOLLEY / ANDROID:JsonArrayRequest 的错误响应
【发布时间】:2015-08-17 09:03:44
【问题描述】:

我在 Android 中使用 Volley 库,但我一直都有 TimeoutError 响应。

我想将 JSONArray 发送到我的 Apache 服务器。 请求后,我收到了 jsonArray,我可以将它存入我的 SqlLite 数据库,但我的 Android 日志中总是出错。

错误:D/MyService(5707):onErrorResponsecom.android.volley.TimeoutError

我的安卓代码:

            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(Method.POST,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);
    }

我的 Laravel/PHP 代码:

    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();

        }
}

如果我添加

            stringRequest.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS*5, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

我现在有这个错误:

onErrorResponsecom.android.volley.ParseError: org.json.JSONException: Value <link of type java.lang.String cannot be converted to JSONArray

【问题讨论】:

    标签: android json http laravel android-volley


    【解决方案1】:

    通过在前面添加以下行来更改默认超时。 queue.add(stringRequest);

    stringRequest.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS*5, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 2019-03-09
      • 1970-01-01
      • 2015-10-07
      • 2019-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多