2
我想加載一個網頁。如何處理webview內部的錯誤?
我想處理網頁加載錯誤。我知道這個錯誤可以在onReceivedError(...)
方法中獲得。
我的問題是如何處理錯誤,而不顯示Page Not found
在webview? (例如:顯示一個對話框,並使webview爲空)。
在此先感謝。
我想加載一個網頁。如何處理webview內部的錯誤?
我想處理網頁加載錯誤。我知道這個錯誤可以在onReceivedError(...)
方法中獲得。
我的問題是如何處理錯誤,而不顯示Page Not found
在webview? (例如:顯示一個對話框,並使webview爲空)。
在此先感謝。
檢查爲:
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{
}
}
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
}
}
是否有可能作出某種錯誤發生的WebView空白? –
看到我的編輯答案 –
我在onReceivedError中顯示了一條警告。但是webview會加載錯誤頁面。 –