本文整理匯總了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();
}
示例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;
}
示例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("未知錯誤");
}
示例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);
}
示例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));
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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 "其他錯誤";
}
}
示例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) {
}
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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());
}