2012-12-05 49 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 
    } 
} 
相關問題