當前位置: 首頁>>代碼示例>>Java>>正文


Java NetworkError類代碼示例

本文整理匯總了Java中com.android.volley.NetworkError的典型用法代碼示例。如果您正苦於以下問題:Java NetworkError類的具體用法?Java NetworkError怎麽用?Java NetworkError使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NetworkError類屬於com.android.volley包,在下文中一共展示了NetworkError類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onErrorResponse

import com.android.volley.NetworkError; //導入依賴的package包/類
@Override
public void onErrorResponse(VolleyError error) {
    error.printStackTrace();
    Log.d("RVA", "error:" + error);

    int errorCode = 0;
    if (error instanceof TimeoutError) {
        errorCode = -7;
    } else if (error instanceof NoConnectionError) {
        errorCode = -1;
    } else if (error instanceof AuthFailureError) {
        errorCode = -6;
    } else if (error instanceof ServerError) {
        errorCode = 0;
    } else if (error instanceof NetworkError) {
        errorCode = -1;
    } else if (error instanceof ParseError) {
        errorCode = -8;
    }
    Toast.makeText(contextHold, ErrorCode.errorCodeMap.get(errorCode), Toast.LENGTH_SHORT).show();
}
 
開發者ID:freedomofme,項目名稱:Netease,代碼行數:22,代碼來源:RequestSingletonFactory.java

示例2: isConnectionError

import com.android.volley.NetworkError; //導入依賴的package包/類
/**
 * 判斷是否有網絡 或者 server無響應等非Client端請求參數異常
 *
 * @param error VolleyError
 * @return isConnectionError
 */
public boolean isConnectionError(VolleyError error) {
    if (error == null) {
        return false;
    }
    if (error instanceof TimeoutError) {
        return true;
    }
    if (error instanceof NoConnectionError) {
        return true;
    }
    if (error instanceof NetworkError) {
        return true;
    }
    if (error instanceof ServerError) {
        return true;
    }
    if (error instanceof RedirectError) {
        return true;
    }
    if (error instanceof AuthFailureError) {
        return true;
    }
    return false;
}
 
開發者ID:xmagicj,項目名稱:HappyVolley,代碼行數:31,代碼來源:BaseRequest.java

示例3: transToOsaException

import com.android.volley.NetworkError; //導入依賴的package包/類
public static OsaException transToOsaException(Throwable a) {
    if (a == null) {
        return new OsaException("未知錯誤");
    }
    if (a instanceof ParseError) {
        return new OsaException("數據解析錯誤", a);
    }
    if (a instanceof TimeoutError) {
        return new OsaException("請求超時", a);
    }
    if (a instanceof ServerError) {
        return new OsaException("服務器錯誤", a);
    }
    if (a instanceof AuthFailureError) {
        return new OsaException("請求認證錯誤", a);
    }
    if (a instanceof NoConnectionError) {
        return new OsaException("網絡未連接,請檢查網絡狀態", a);
    }
    if (a instanceof NetworkError) {
        return new OsaException("網絡連接異常", a);
    }
    return new OsaException("未知錯誤");
}
 
開發者ID:likebamboo,項目名稱:AndroidBlog,代碼行數:25,代碼來源:ErrorTrans.java

示例4: deliverError

import com.android.volley.NetworkError; //導入依賴的package包/類
@Override
public void deliverError(VolleyError error) {
    statusCode = error.networkResponse != null ? error.networkResponse.statusCode : 0;

    String msgError = null;
    if (error instanceof NetworkError) {
        msgError = "Failed to connect to server";

    } else if (error instanceof TimeoutError) {
        msgError = "Timeout for connection exceeded";
    } else {
        if (error.networkResponse != null && error.networkResponse.data != null && !error.networkResponse.data.equals("")) {
            try {
                msgError = new String(error.networkResponse.data, PROTOCOL_CHARSET);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        } else {
            msgError = error.getMessage();
        }
    }

    this.onPlainRequest.onError(error, msgError, statusCode);
}
 
開發者ID:giovanimoura,項目名稱:plainrequest,代碼行數:25,代碼來源:RequestCustom.java

示例5: queryZSuperweaponProgress

import com.android.volley.NetworkError; //導入依賴的package包/類
/**
 * Queries the user's superweapon progress.
 */
private void queryZSuperweaponProgress() {
    NSStringRequest stringRequest = new NSStringRequest(getApplicationContext(), Request.Method.GET, ZSuperweaponProgress.ZOMBIE_CONTROL_QUERY,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    processZSuperweaponProgress(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            SparkleHelper.logError(error.toString());
            mSwipeRefreshLayout.setRefreshing(false);
            if (error instanceof TimeoutError || error instanceof NoConnectionError || error instanceof NetworkError) {
                SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_no_internet));
            } else {
                SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_generic));
            }
        }
    });

    if (!DashHelper.getInstance(this).addRequest(stringRequest)) {
        mSwipeRefreshLayout.setRefreshing(false);
        SparkleHelper.makeSnackbar(mView, getString(R.string.rate_limit_error));
    }
}
 
開發者ID:lloydtorres,項目名稱:stately,代碼行數:29,代碼來源:ZombieControlActivity.java

示例6: get

import com.android.volley.NetworkError; //導入依賴的package包/類
public static String get(Context paramContext, VolleyError paramVolleyError)
{
  if ((paramVolleyError instanceof DisplayMessageError)) {
    return ((DisplayMessageError)paramVolleyError).mDisplayErrorHtml;
  }
  if ((paramVolleyError instanceof AuthFailureError)) {
    return paramContext.getString(2131361869);
  }
  if ((paramVolleyError instanceof ServerError)) {
    return paramContext.getString(2131362721);
  }
  if ((paramVolleyError instanceof TimeoutError)) {
    return paramContext.getString(2131362787);
  }
  if ((paramVolleyError instanceof NetworkError)) {
    return paramContext.getString(2131362362);
  }
  FinskyLog.d("No specific error message for: %s", new Object[] { paramVolleyError });
  return paramContext.getString(2131362362);
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:21,代碼來源:ErrorStrings.java

示例7: convertErrorCode

import com.android.volley.NetworkError; //導入依賴的package包/類
private static int convertErrorCode(Throwable paramThrowable)
{
  if ((paramThrowable instanceof ServerError)) {
    return -1;
  }
  if ((paramThrowable instanceof NetworkError)) {
    return -2;
  }
  if ((paramThrowable instanceof AuthFailureError)) {
    return -3;
  }
  if ((paramThrowable instanceof TimeoutError)) {
    return -4;
  }
  return 0;
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:17,代碼來源:BillingAccountService.java

示例8: isNetworkingError

import com.android.volley.NetworkError; //導入依賴的package包/類
public static boolean isNetworkingError(VolleyError volleyError)
{
    if (volleyError.networkResponse == null) {
        if (volleyError instanceof TimeoutError) {
           return true;
        }

        if (volleyError instanceof NoConnectionError) {
            return true;
        }

        if (volleyError instanceof NetworkError) {
            return true;
        }

    }
    return false;
}
 
開發者ID:lemberg,項目名稱:android-project-template,代碼行數:19,代碼來源:VolleyResponseUtils.java

示例9: showError

import com.android.volley.NetworkError; //導入依賴的package包/類
private void showError(VolleyError error) {
    //In your extended request class
    dismissProgressBar();
    if (error.networkResponse != null && error.networkResponse.data != null) {
        VolleyError volleyError = new VolleyError(new String(error.networkResponse.data));
        volleyError.printStackTrace();
    }
    if (error instanceof NetworkError) {
        showToast(NETWORK_ERROR);
    } else if (error instanceof ServerError) {
        showToast(SERVER_ERROR);
    } else if (error instanceof NoConnectionError) {
        showToast(NO_INTERNET_CONNECTION);
    } else if (error instanceof TimeoutError) {
        showToast(CONNECTION_TIME_OUT);
    } else {
        showToast(UNKNOWN_ERROR);
    }

}
 
開發者ID:nishant-git,項目名稱:social-api,代碼行數:21,代碼來源:ServerRequest.java

示例10: handlerException

import com.android.volley.NetworkError; //導入依賴的package包/類
public String handlerException(VolleyError error) {

        if (error instanceof TimeoutError || error instanceof NoConnectionError) {
            return "連接服務器失敗";
        } else if (error instanceof AuthFailureError) {
            return "服務器驗證失敗";
        } else if (error instanceof ServerError) {
            return "服務器出錯了";
        } else if (error instanceof NetworkError) {
            return "網絡異常";
        } else if (error instanceof ParseError) {
            return "數據解析異常";
        } else {
            Log.d("error", error.toString());
            return "其他錯誤";
        }
    }
 
開發者ID:Tangyingqi,項目名稱:Jiemian,代碼行數:18,代碼來源:BasePresenter.java

示例11: onErrorResponse

import com.android.volley.NetworkError; //導入依賴的package包/類
@Override
public void onErrorResponse(VolleyError e) {
    if (e.networkResponse != null)
        Log.d(ErrorResponseListener.class, "Network Error", "" + e.networkResponse.statusCode + " " + String.valueOf(e.networkResponse.data));
    // Handle your error types accordingly.For Timeout & No connection error, you can show 'retry' button.
    // For AuthFailure, you can re login with user credentials.
    // For ClientError, 400 & 401, Errors happening on client side when sending api request.
    // In this case you can check how client is forming the api and debug accordingly.
    // For ServerError 5xx, you can do retry or handle accordingly.
    if (e instanceof AuthFailureError) {
        Intent intent = new Intent(Constants.AUTH_FAILURE_BROADCAST_EVENT);
        context.sendBroadcast(intent);
        Log.d(ErrorResponseListener.class, "AuthFailureError: ", e.getStackTrace().toString());
    } else if (e instanceof NetworkError) {
    } else if (e instanceof ServerError) {
    } else if (e instanceof ParseError) {
    } else if (e instanceof NoConnectionError) {
    } else if (e instanceof TimeoutError) {
    }
}
 
開發者ID:RandoApp,項目名稱:Rando-android,代碼行數:21,代碼來源:ErrorResponseListener.java

示例12: fetchData

import com.android.volley.NetworkError; //導入依賴的package包/類
private void fetchData() {
    wheel.setVisibility(View.VISIBLE);
    RequestQueue requestQueue = VolleySingleton.getInstance().getRequestQueue();
    StringRequest req = new StringRequest(Request.Method.GET, API.BASE_IMAGE_URL + showID + "/actors.xml",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    new loadData().execute(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                tvError.setText(R.string.timeout_error);
            } else if (error instanceof ServerError) {
                tvError.setText(R.string.server_error);
            } else if (error instanceof NetworkError) {
                tvError.setText(R.string.network_error);
            } else {
                tvError.setText(R.string.connection_error);
            }
            tapToRetry.setVisibility(View.VISIBLE);
            wheel.setVisibility(View.GONE);
        }
    });
    requestQueue.add(req);
}
 
開發者ID:chashmeetsingh,項目名稱:TrackIt-Android,代碼行數:28,代碼來源:ActorDetailActivity.java

示例13: handleNetworkError

import com.android.volley.NetworkError; //導入依賴的package包/類
private void handleNetworkError(VolleyError error) {
    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        getView().showTimeOutError();
    } else if (error instanceof ServerError) {
        getView().show500ServerError();
    } else if (error instanceof NetworkError) {
        getView().showNetworkError();
    }
}
 
開發者ID:narenkukreja,項目名稱:quire,代碼行數:10,代碼來源:UpdateUserListingPresenter.java

示例14: handleErrors

import com.android.volley.NetworkError; //導入依賴的package包/類
private void handleErrors(VolleyError error) {
    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        getView().showTimeOutError();
    } else if (error instanceof ServerError) {
        getView().show500ServerError();
    } else if (error instanceof NetworkError) {
        getView().showNetworkError();
    }
}
 
開發者ID:narenkukreja,項目名稱:quire,代碼行數:10,代碼來源:ListNewItemPresenter.java

示例15: parseError

import com.android.volley.NetworkError; //導入依賴的package包/類
private Response<T> parseError(VolleyError error, BaseRequest request) {
    HttpResponse.Builder builder = new HttpResponse.Builder()
            .success(false)
            .request(request)
            .message(error.getMessage());

    if (error instanceof NetworkError || error instanceof TimeoutError) {
        VolleyLog.e("Network error.");
        if (error.getCause() instanceof SSLHandshakeException) {
            VolleyLog.e("SSLHandshakeException: Insecure connection");
        }
        return Response.error(builder.build());
    }

    NetworkResponse response = error.networkResponse;
    if (response == null) {
        VolleyLog.e("Local error.");
        return Response.error(builder.build());
    }

    String json = "";
    if (response.data != null) {
        json = new String(response.data);
    }
    ResponseBody body = ResponseBody.create(MediaType.parse(response.headers.get("Content-Type")), json);
    return Response.error(body, builder.raw(json).code(response.statusCode).build());
}
 
開發者ID:octaware,項目名稱:super-volley,代碼行數:28,代碼來源:VolleyCall.java


注:本文中的com.android.volley.NetworkError類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。