本文整理匯總了Java中com.android.volley.NoConnectionError類的典型用法代碼示例。如果您正苦於以下問題:Java NoConnectionError類的具體用法?Java NoConnectionError怎麽用?Java NoConnectionError使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NoConnectionError類屬於com.android.volley包,在下文中一共展示了NoConnectionError類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onErrorResponse
import com.android.volley.NoConnectionError; //導入依賴的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: onErrorResponse
import com.android.volley.NoConnectionError; //導入依賴的package包/類
@Override
public void onErrorResponse(VolleyError error) {
if (error instanceof TimeoutError || error instanceof NoConnectionError) {
// Is thrown if there's no network connection or server is down
Toast.makeText(context, getString(R.string.error_network_timeout),
Toast.LENGTH_LONG).show();
// We return to the last fragment
if (getFragmentManager().getBackStackEntryCount() != 0) {
getFragmentManager().popBackStack();
}
} else {
// Is thrown if there's no network connection or server is down
Toast.makeText(context, getString(R.string.error_network),
Toast.LENGTH_LONG).show();
// We return to the last fragment
if (getFragmentManager().getBackStackEntryCount() != 0) {
getFragmentManager().popBackStack();
}
}
}
示例3: isConnectionError
import com.android.volley.NoConnectionError; //導入依賴的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;
}
示例4: transToOsaException
import com.android.volley.NoConnectionError; //導入依賴的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("未知錯誤");
}
示例5: getErrorListener
import com.android.volley.NoConnectionError; //導入依賴的package包/類
private Response.ErrorListener getErrorListener(final Listener l) {
return new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error instanceof NoConnectionError) {
l.onFailure("Network is unreachable. Please check your internet connection.");
} else if (error.networkResponse.statusCode == 401 || error.networkResponse.statusCode == 403) {
l.onFailure("Invalid credentials or not enough permissions");
} else if (error.networkResponse.statusCode == 400) {
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode json = mapper.readTree(new String(error.networkResponse.data));
l.onFailure("Error: " + json.get("message").asText());
} catch (IOException e) {
l.onFailure(new String(error.networkResponse.data));
}
} else {
l.onFailure(error.getMessage());
}
}
};
}
示例6: showErrorDialog
import com.android.volley.NoConnectionError; //導入依賴的package包/類
/**
* Show an error dialog based on the exception
*
* @param exception The exception which occurred
* @param context The current context
* @param finish Whether or not to finish this activity
* @return The dialog which is shown
*/
public static void showErrorDialog(final Exception exception, final Activity context, final boolean finish) {
if (exception instanceof ServerError) {
if (((ServerError) exception).networkResponse != null) {
if (((ServerError) exception).networkResponse.statusCode == 404) {
showNotFoundErrorDialog(context, finish);
} else if (((ServerError) exception).networkResponse.statusCode == 500) {
showServerErrorDialog(context, finish);
} else {
showServerErrorDialog(context, finish);
}
} else {
showGeneralErrorDialog(context, finish);
}
} else if (exception instanceof NoConnectionError){
showNetworkErrorDialog(context, finish);
} else {
showGeneralErrorDialog(context, finish);
}
}
示例7: checkErrorType
import com.android.volley.NoConnectionError; //導入依賴的package包/類
public static String checkErrorType(VolleyError error) {
String str = "";
if (error instanceof NoConnectionError) {
str = ErrorCode.IS_NOT_NETWORK;
} else if (error instanceof AuthFailureError) {
str = ErrorCode.AUTH_FAILED;
} else if (error instanceof TimeoutError) {
str = ErrorCode.CONNECTION_TIMEOUT;
} else if (error instanceof ParseError) {
str = ErrorCode.PARSE_DATA_ERROR;
} else if (error instanceof ServerError) {
str = ErrorCode.SERVER_ERROR;
} else if (error instanceof HttpError) {
HttpError httpError = (HttpError) error;
str = httpError.getMessage();
if (TextUtils.isEmpty(str)) {
str = ErrorCode.REQUEST_ERROR;
}
} else {
str = ErrorCode.REQUEST_ERROR;
}
return str;
}
示例8: queryZSuperweaponProgress
import com.android.volley.NoConnectionError; //導入依賴的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));
}
}
示例9: deliverError
import com.android.volley.NoConnectionError; //導入依賴的package包/類
@Override
public void deliverError(VolleyError error) {
Log.i("CustomRequest", "deliverError----" + error.getMessage());
if (error instanceof NoConnectionError && mRequestBody == null) {
Cache.Entry entry = this.getCacheEntry();
if (entry != null) {
Log.d("CustomRequest", " deliverError--------: " + new String(entry.data));
if (entry.data != null && entry.responseHeaders != null) {
Response<T> response = parseNetworkResponse(new NetworkResponse(entry.data, entry.responseHeaders));
if (response.result != null) {
deliverResponse(response.result);
return;
}
}
}
}
super.deliverError(error);
}
示例10: isNetworkingError
import com.android.volley.NoConnectionError; //導入依賴的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;
}
示例11: showError
import com.android.volley.NoConnectionError; //導入依賴的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);
}
}
示例12: handlerException
import com.android.volley.NoConnectionError; //導入依賴的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 "其他錯誤";
}
}
示例13: errorFromVolley
import com.android.volley.NoConnectionError; //導入依賴的package包/類
/**
* Helper method to create a RecurlyError from a VolleyError
*
* @param volleyError The underlying error causing the exception
* @return An instance of RecurlyError
*/
public static RecurlyError errorFromVolley(VolleyError volleyError) {
if (volleyError instanceof NetworkResponseError) {
return new RecurlyError((NetworkResponseError) volleyError);
}
RecurlyError error = new RecurlyError();
String responseBody = null;
if (volleyError.networkResponse != null && volleyError.networkResponse.data != null) {
responseBody = new String(volleyError.networkResponse.data);
}
if (!(volleyError instanceof NoConnectionError)) {
volleyError.printStackTrace();
}
if (volleyError.networkResponse != null) {
error.mStatusCode = volleyError.networkResponse.statusCode;
}
error.mErrorMessage = volleyError.getLocalizedMessage();
error.mErrorCode = volleyError.getMessage();
return error;
}
示例14: parseVolleyError
import com.android.volley.NoConnectionError; //導入依賴的package包/類
/**
* Parses any given errors from the underlying Volley mechanism into SDK defined error types.
*
* @param volleyError
* The Volley error to parse.
*
* @return The corresponding SDK defined error object.
*/
private PodioError parseVolleyError(VolleyError volleyError) {
PodioError error;
if (volleyError instanceof NoConnectionError && volleyError.getCause() instanceof UnknownHostException) {
error = new ConnectionError(volleyError);
} else if (volleyError instanceof TimeoutError) {
error = new NoResponseError(volleyError);
} else {
String errorJson = getResponseBody(volleyError.networkResponse);
int responseCode = getResponseCode(volleyError.networkResponse);
if (Utils.notEmpty(errorJson) && responseCode > 0) {
error = new ApiError(errorJson, responseCode, volleyError);
} else {
error = new PodioError(volleyError);
}
}
return error;
}
示例15: getErrorListener
import com.android.volley.NoConnectionError; //導入依賴的package包/類
private ErrorListener getErrorListener(final ProgressDialog progressDialog) {
return new ErrorListener() {
@Override
public void onErrorResponse(final VolleyError arg0) {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
String error = getResources().getString(R.string.login_error);
if (arg0 instanceof NoConnectionError) {
error = getResources().getString(R.string.connection_error);
}
Toast.makeText(
HomeActivity.this, error, Toast.LENGTH_LONG).show();
}
};
}