在使用WebView中,我们不可避免的会接触到WebView加载失败的异常处理的需求,这时候,需要我们监听失败的方法也就是onReceivedError方法:

public class CustomWebViewClient extends WebViewClient {

    @Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (error.getErrorCode() == ERROR_HOST_LOOKUP) {
view.loadUrl("about:blank");
}
}
} @Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
if (errorCode == ERROR_HOST_LOOKUP) {
view.loadUrl("about:blank");
}
}
}
}

下面是errorCode的列举

/** Generic error */
public static final int ERROR_UNKNOWN = -1;
/** Server or proxy hostname lookup failed */
public static final int ERROR_HOST_LOOKUP = -2;
/** Unsupported authentication scheme (not basic or digest) */
public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
/** User authentication failed on server */
public static final int ERROR_AUTHENTICATION = -4;
/** User authentication failed on proxy */
public static final int ERROR_PROXY_AUTHENTICATION = -5;
/** Failed to connect to the server */
public static final int ERROR_CONNECT = -6;
/** Failed to read or write to the server */
public static final int ERROR_IO = -7;
/** Connection timed out */
public static final int ERROR_TIMEOUT = -8;
/** Too many redirects */
public static final int ERROR_REDIRECT_LOOP = -9;
/** Unsupported URI scheme */
public static final int ERROR_UNSUPPORTED_SCHEME = -10;
/** Failed to perform SSL handshake */
public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
/** Malformed URL */
public static final int ERROR_BAD_URL = -12;
/** Generic file error */
public static final int ERROR_FILE = -13;
/** File not found */
public static final int ERROR_FILE_NOT_FOUND = -14;
/** Too many requests during this load */
public static final int ERROR_TOO_MANY_REQUESTS = -15;

WebView 错误码整理的更多相关文章

  1. sqlite3错误码整理

    #define SQLITE_OK /* 成功 | Successful result */ /* 错误码开始 */ #define SQLITE_ERROR /* SQL错误 或 丢失数据库 | S ...

  2. Android项目实战(五十六):获取WebView加载的url的请求错误码

    例如需求,我有一个WebView 加载一个url, 该url对应的网页本身自带下拉刷新 ,但是网页本身会有出现400 500 等异常请求错误码 这时候网页加载失败,页面本身的下拉是无法使用的,要求重新 ...

  3. 【Fine原创】常见的HTTP错误码的具体含义整理

    常见的HTTP错误码的具体含义     "100" : Continue   客户端应当继续发送请求. "101" : witching Protocols   ...

  4. SMTP错误码建议解决方法

    https://wenku.baidu.com/view/0af30e01e87101f69e3195b8.html SMTP 错误码 / 建议解决方法 错误总表 101 Cannot Open Co ...

  5. 微信小程序错误码参考大全

    开发过程中,会遇到很多微信返回的状态码,鬼知道代表什么意思,现在好了,整理总结了一份状态码,方便大家. 转载:http://www.yiyongtong.com/archives/view-1856- ...

  6. 【SMTP】常见错误码

    '* 邮件服务返回代码含义 '* 500 格式错误,命令不可识别(此错误也包括命令行过长) '* 501 参数格式错误 '* 502 命令不可实现 '* 503 错误的命令序列 '* 504 命令参数 ...

  7. UTF-8,Unicode,GBK,希腊字母读法,ASCII码表,HTTP错误码,URL编码表,HTML特殊字符,汉字编码简明对照表

    UNICODE,GBK,UTF-8区别 UNICODE,GBK,UTF-8区别    简单来说,unicode,gbk和大五码就是编码的值,而utf-8,uft-16之类就是这个值的表现形式.而前面那 ...

  8. Smtp错误码

    Smtp错误码列表及相关原因 错误总表 420 1. Timeout Communication Problem Encountered During Transmission. Thie Is a ...

  9. Windows下错误码全解析

    windows系统下,调用函数出错时.可以调用GetLastError函数返回错误码.但是GetLastError函数返回值是DWORD类型,是一个整数.如果想要知道函数调用的真正错误原因,就需要对这 ...

随机推荐

  1. 一分钟搭建Spring Boot

    1.首先你的电脑需要安装jdk.Apache Maven.Intellij IDEA 2.新建项目  (敲重点,有的同学有没有Spring Initializr 这个请到本文章后面看安装步骤) 3.选 ...

  2. Windows下用VS2015+MSYS编译OpenH264

    因为项目用到了OpenH264,编译的过程不想做过多研究,搜了下,有网页可以参考,遂记录下来,并在后面做一些补充. 原帖地址:http://blog.csdn.net/dbyoung/article/ ...

  3. A除以B

    1017 A除以B (20)(20 分) 本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数.你需要输出商数Q和余数R,使得A = B * Q + R成立. 输入格式: 输入在1行中 ...

  4. Spring MVC 自动为对象注入枚举类型

    原文地址:http://1358440610-qq-com.iteye.com/blog/2079048 如果一个对象里面有枚举类型的话,则Spring MVC是不能够直接进行注入的,因为它只实现了一 ...

  5. Python开发【第七篇】:面向对象二

    字段 class Foo:     #静态字段(保存在类中)     CC = 123       def __init__(self):         #普通字段(保存在对象中)          ...

  6. TZOJ 4602 高桥和低桥(二分或树状数组+二分)

    描述 有个脑筋急转弯是这样的:有距离很近的一高一低两座桥,两次洪水之后高桥被淹了两次,低桥却只被淹了一次,为什么?答案是:因为低桥太低了,第一次洪水退去之后水位依然在低桥之上,所以不算“淹了两次”.举 ...

  7. T-codes & Rarely Seen Tables(Updated from previous note)

    T-codes C CO CO01/02/03:Production Order CG CG3Y:Download file from server,never used this before CM ...

  8. [leetcode]44. Wildcard Matching万能符匹配

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...

  9. Python开发——数据类型【集合】

    集合的定义 由一个或多个确定的元素所构成的整体 可变集合 s=set('hello') print(s) # {'e', 'l', 'o', 'h'} s=set(['alex','alex','Lu ...

  10. Pandas 合并 concat

    pandas处理多组数据的时候往往会要用到数据的合并处理,使用 concat是一种基本的合并方式.而且concat中有很多参数可以调整,合并成你想要的数据形式. 1.axis(合并方向):axis=0 ...