当前位置: 首页>>代码示例>>Java>>正文


Java NoConnectionError类代码示例

本文整理汇总了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();
}
 
开发者ID:freedomofme,项目名称:Netease,代码行数:22,代码来源:RequestSingletonFactory.java

示例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();
            }
    }
}
 
开发者ID:michaelachmann,项目名称:LnkShortener,代码行数:23,代码来源:SetupActivity.java

示例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;
}
 
开发者ID:xmagicj,项目名称:HappyVolley,代码行数:31,代码来源:BaseRequest.java

示例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("未知错误");
}
 
开发者ID:likebamboo,项目名称:AndroidBlog,代码行数:25,代码来源:ErrorTrans.java

示例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());
            }
        }
    };
}
 
开发者ID:aomega08,项目名称:Keep-HODLing,代码行数:23,代码来源:GdaxApi.java

示例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);
    }
}
 
开发者ID:hyperrail,项目名称:hyperrail-for-android,代码行数:28,代码来源:ErrorDialogFactory.java

示例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;
}
 
开发者ID:DoloresTeam,项目名称:dolores-android,代码行数:24,代码来源:HttpUtil.java

示例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));
    }
}
 
开发者ID:lloydtorres,项目名称:stately,代码行数:29,代码来源:ZombieControlActivity.java

示例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);
}
 
开发者ID:macouen,项目名称:lunzi,代码行数:19,代码来源:CustomRequest.java

示例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;
}
 
开发者ID:lemberg,项目名称:android-project-template,代码行数:19,代码来源:VolleyResponseUtils.java

示例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);
    }

}
 
开发者ID:nishant-git,项目名称:social-api,代码行数:21,代码来源:ServerRequest.java

示例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 "其他错误";
        }
    }
 
开发者ID:Tangyingqi,项目名称:Jiemian,代码行数:18,代码来源:BasePresenter.java

示例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;
}
 
开发者ID:recurly,项目名称:recurly-client-android,代码行数:30,代码来源:RecurlyError.java

示例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;
}
 
开发者ID:podio,项目名称:podio-android,代码行数:29,代码来源:ImageLoader.java

示例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();
		}
	};
}
 
开发者ID:Monits,项目名称:AgilefantAndroid,代码行数:20,代码来源:HomeActivity.java


注:本文中的com.android.volley.NoConnectionError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。