随机com.android.volley.NoConnection错误,java.io.InterruptedIOException,statuscode = 0 [英] random com.android.volley.NoConnection error, java.io.InterruptedIOException, statuscode=0

查看:155
本文介绍了随机com.android.volley.NoConnection错误,java.io.InterruptedIOException,statuscode = 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个原生的Android应用程序,使用volley框架从 PHP 服务器端脚本中获取数据。

I have a native android app using volley framework to fetch data from a PHP server end script.

它在大多数时候运作良好,但我有20%的失败率。

It worked well on most time, but I have 20% percentage failure.

错误说:


com.android.volley.NoConnection,java .io.InterruptedIOException。

com.android.volley.NoConnection, java.io.InterruptedIOException.

我调试了我发现 statuscode = 0 ,这显然是错的。

I debugged that I found the statuscode = 0, which obviously was wrong.

我不知道是什么原因?因为它工作时间最长,所以不应该有明显的错误代码。

I have no idea what can be the reason? Since it is working most time so there should be no obvious error code.

仅供参考,服务器端的那些PHP脚本对我的IOS应用程序非常有效。

FYI, those PHP script on the server end works very well for my IOS app.

请允许我在此处发布我的代码:

Please allow me post my code here:

retryConnBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            txtOut.append("\n");
            txtOut.append("Button with Retry Click");
            Log.d("Click", "Button Click");
            final String url = "https://www.myserver.com/api/getBalanceInfoTest?token=7ff3317a4f3dc07d0c297a7d16d2049c&t=" + System.currentTimeMillis();
            //final String url = "http://192.168.1.23/base/test/";
            JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, null,
                    new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {
                            txtOut.append("\n");
                            txtOut.append("Result with Retry:");
                            txtOut.append(response.toString());
                            Log.d("Response", response.toString());
                            VolleyLog.e("Response:", response.toString());
                        }
                    },
                    new Response.ErrorListener(){
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            txtOut.append("\n");
                            txtOut.append("Error with Retry:");
                            txtOut.append(error.toString());
                            Log.d("Error.Response", error.toString());
                            VolleyLog.e("Error:", error.getMessage());
                        }
                    });

            getRequest.setRetryPolicy(new DefaultRetryPolicy(5000, 5, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
            queue.add(getRequest);
            queue.start();
        }
    });


}

有关更多信息,请输出我的 PHP 脚本是:
{hsaBalance:1000.00} ,由<$ c创建$ c> Json_encode() PHP的函数

And for more information, the output of my PHP script is: {"hsaBalance":"1000.00"}, created by Json_encode() function of PHP.

推荐答案

我修复了这个bug。
这不是网络问题。

I have fixed this bug. It is not a network issue.

queue.add(getRequest);
queue.start();

应该是

queue.add(getRequest);

所以关键是我们应该删除 queue.start()

So the key is we should remove queue.start().

这篇关于随机com.android.volley.NoConnection错误,java.io.InterruptedIOException,statuscode = 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆