当请求的 URL 无效时,控制器永远不会使用“onReceivedError”方法。但是在加载有效页面时,会正确调用“onProgressChanged”。
代码:
try {
webView = (WebView) findViewById(R.id.webViewEvents);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
System.out.println("on Progress Changes : ");
}
});
webView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
System.out.println("on Error received : ");
}
});
webView.loadUrl("http://google.com");
} catch (Exception e) {
System.out.println("Exception while loading: " + e);
}