Java 在android中多次显示没有互联网连接

Java 在android中多次显示没有互联网连接,java,android,json,android-studio,android-volley,Java,Android,Json,Android Studio,Android Volley,我正在使用JsonArrayRequest将json数据检索到我的android应用程序中。一切正常,但很多时候它显示网络错误我设置了超时。。。!没有互联网Toast。但我有网络连接,甚至显示网络错误。我正在使用OnErrorResponse: private void jsonrequest() { request = new JsonArrayRequest(JSON_URL, new Response.Listener<JSONArray>() {

我正在使用
JsonArrayRequest
将json数据检索到我的android应用程序中。一切正常,但很多时候它显示
网络错误
我设置了
超时。。。!没有互联网
Toast。但我有网络连接,甚至显示网络错误。我正在使用OnErrorResponse:

private void jsonrequest() {

        request = new JsonArrayRequest(JSON_URL, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                loading.setVisibility(View.GONE);
                JSONObject jsonObject  = null ;

                for (int i = 0 ; i < response.length(); i++ ) {


                    try {
                        jsonObject = response.getJSONObject(i) ;
                        Anime anime = new Anime() ;
                        anime.setName(jsonObject.getString("title"));
                        anime.setDescription(jsonObject.getString("description"));
                        anime.setRating(jsonObject.getString("date"));
                        anime.setCategorie(jsonObject.getString("category"));
                        anime.setStudio(jsonObject.getString("admin"));
                        anime.setImage_url(jsonObject.getString("thumbnail"));
                        lstAnime.add(anime);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


                }

                setuprecyclerview(lstAnime);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                    //This indicates that the request has either time out or there is no connection
                    Toast.makeText(MainActivity.this, "TimeOut...! No Internet",
                            Toast.LENGTH_LONG).show();

                } else if (error instanceof AuthFailureError) {
                    // Error indicating that there was an Authentication Failure while performing the request
                    Toast.makeText(MainActivity.this, "Failed To Receive Data",
                            Toast.LENGTH_LONG).show();

                } else if (error instanceof ServerError) {
                    //Indicates that the server responded with a error response
                    Toast.makeText(MainActivity.this, "Our Server Under Maintenance",
                            Toast.LENGTH_LONG).show();
                } else if (error instanceof NetworkError) {
                    //Indicates that there was network error while performing the request
                    Toast.makeText(MainActivity.this, "Network Not Responding",
                            Toast.LENGTH_LONG).show();
                } else if (error instanceof ParseError) {
                    // Indicates that the server response could not be parsed
                    Toast.makeText(MainActivity.this, "Please Reload Again!",
                            Toast.LENGTH_LONG).show();
                }
            }
        });


        requestQueue = Volley.newRequestQueue(MainActivity.this);
        requestQueue.add(request) ;


    }
private void jsonrequest(){
request=newjsonarrayrequest(JSON_URL,newresponse.Listener(){
@凌驾
公共void onResponse(JSONArray响应){
loading.setVisibility(View.GONE);
JSONObject JSONObject=null;
对于(int i=0;i
我不明白问题出在哪里?你能帮我解决这个问题吗


谢谢。

您是在url中使用localhost还是在任何本地服务器上运行应用程序?那你肯定有连接问题了。@ShamsulArafinMahtab不。。。我正在从我的高级主机运行api。