在使用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. Elasticsearch 整合spring(不是sprig boot)

    公司做统计任务,有使用Es做聚合操作,使用的是自己封装的版本,这边整合下原生spring,做下学习记录,随便看一下,发现差不多都是spring boot的案例...我该怎么办,...发现整合的过程其实 ...

  2. 前端 搜索样式 html

    原文:https://blog.csdn.net/linlinxie/article/details/77484214?utm_source=blogkpcl4 测试1: <div class= ...

  3. cdnbest架设cdn同一个源用不同的端口访问如何设置

    在站点里的应用防火墙-->高级设置里配置 比如test.com要同时用80和88访问

  4. linux 大容量磁盘分区工具parted

    1. Msdos和Gpt的区别 fdisk  :只能分msdos分区parted :可以分msdos和gpt分区 2. MSDOS特点最大支持2TB卷大小.每个磁盘最多只能有4个主分区(或3个主分区, ...

  5. 3. Go语言基本类型

    Go语言基本类型如下: bool string 数值类型 (int8, int16, int32, int64, int, uint8, uint16, uint32, uint64, uint, f ...

  6. AngularJS学习笔记(一)

    一.基本指令 1.ng-app=" " 指令初始化一个 AngularJS 应用程序,定义angularJS的使用范围; tips:一个页面里创建多个 ng-app 手动加载即可: ...

  7. extern和include的作用

    首先要搞清楚的是.h头文件中都是一些声明性的语句,是不分配内存的,所以头文件中有对函数的声明,有define语句,有没有实例化的结构体定义,但是没有对变量的定义(比如 int a),有的只是对外变量的 ...

  8. vue.js中内联样式style三元表达式

    <span v-bind:style="{'display':config.isHaveSearch ? 'block':'none'}" >搜索</span&g ...

  9. node.js中使用socket.io + express进行实时消息推送

    socket.io是一个websocket库,包含客户端的js和服务端的node.js,可以在不同浏览器和移动设备上构建实时应用. 一.安装 socket.io npm install socket. ...

  10. python基础之Day7part1集合

    一.集合 1.定义 s=set() 2.特点 每个元素必须是不可变类型,但集合本身是可变类型的,有add和remove等功能 3.用途 去重(原理:for循环if判断元素是否已存在,不存在则追加) 关 ...