Ben
Ben

Reputation: 62384

abstract method not being picked up

I'm getting the following error: The type new MyWebViewClient(){} must implement the inherited abstract method MyWebViewClient.launchExternalBrowser()

    DCWebView.setWebViewClient(new MyWebViewClient() {
        public void launchExternalBrowser(String url) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
        }
    });

I don't understand because according to my code I am defining the method.

public abstract class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("www.url.com")) {
            // This is my web site, so do not override; let my WebView load the page
            return false;
        }
        // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
        launchExternalBrowser();
        return true;
    }

    public abstract void launchExternalBrowser();
}

Upvotes: 1

Views: 108

Answers (5)

Android Killer
Android Killer

Reputation: 18489

Change the method launchExternalBrowser() as like this inside MyWebViewClient like this:

public void launchExternalBrowser(){

}

Upvotes: 0

Boaz
Boaz

Reputation: 4669

you are implementing public void launchExternalBrowser(String url) instead of implementing public void launchExternalBrowser() the difference is in the parameter list of the method

Upvotes: 1

miku
miku

Reputation: 188024

You override the method with one argument, while the compiler seems to complain about a method with no argument. Maybe you'll need to override both (or just the one without any arguments - depending on the abstract class).

Upvotes: 0

Ronald Wildenberg
Ronald Wildenberg

Reputation: 32094

You forgot to include the string parameter in the abstract declaration of launchExternalBrowser.

Upvotes: 0

unholysampler
unholysampler

Reputation: 17321

public void launchExternalBrowser(String url)

is not the same as

public abstract void launchExternalBrowser();

To satisfy the class implementation, you have to implement a function with the exact same signature as the abstract method. If you want to passing in a string as an argument, you must define the method that was in the abstract class.

Upvotes: 1

Related Questions