2012-12-05 57 views
2

我想加载一个网页。如何处理webview内部的错误?

​​

我想处理网页加载错误。我知道这个错误可以在onReceivedError(...)方法中获得。

我的问题是如何处理错误,而不显示Page Not found在webview? (例如:显示一个对话框,并使webview为空)。

在此先感谢。

回答

7

检查为:

public void onReceivedError(WebView view, int errorCode, 
          String description, String failingUrl) { 
      Log.e("ProcessPayment", "onReceivedError = " + errorCode); 

      //404 : error code for Page Not found 
      if(errorCode==404){ 
       // show Alert here for Page Not found 
       view.loadUrl("file:///android_asset/Page_Not_found.html"); 
      } 
      else{ 

       } 
      } 
+0

是否有可能作出某种错误发生的WebView空白? –

+0

看到我的编辑答案 –

+0

我在onReceivedError中显示了一条警告。但是webview会加载错误页面。 –

0
public void onReceivedError(WebView view, int errorCode, String description, 
     String failingUrl) { 

    if (errorCode == ERROR_HOST_LOOKUP || errorCode == ERROR_FILE_NOT_FOUND) { 
     // TODO your dialog here 
    } 
} 
相关问题