0

I'm trying to display web page using WebView in android, when a particular page doesn't load, it displays error message with URL, saying that abcd.com is not available, how do I replace the error message with my custom message instead of displaying the URL?

    storeLocator.setWebViewClient(new WebViewClient(){

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            storeLocator.loadUrl("file:///assets/error.html");

        }
        });
        storeLocator.loadUrl("http://goog.c");
Anil M
  • 1,297
  • 2
  • 19
  • 42
  • See this question: http://stackoverflow.com/questions/5433818/android-webviewclient-onreceivederror-is-not-called-for-a-404-error – Tushar Mar 30 '13 at 06:57
  • @Tushar yeah I think 404's not being caught!! check this: [link](http://stackoverflow.com/questions/5124052/android-webviewclient-onerrorreceived-not-being-called-when-there-is-a-404) – Anil M Mar 30 '13 at 07:01

1 Answers1

2

You can create the html page whatever you want to show whenever the error comes or your page is not available ,the code is given here-

webview.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                webview.loadUrl("file:///android_asset/myerrorpage.html");

            }
        });
Ravi
  • 2,277
  • 3
  • 22
  • 37
  • have you tested this code? While it seems like it should work, I heard that there's a bug in the SDK that causes this not to report `404` errors. – Tushar Mar 30 '13 at 06:49
  • @Tushar I tried to implement, but its still showing the same error message instead of my custom message!! Implementation is in edited part.. – Anil M Mar 30 '13 at 06:53