抽象的方法没被拿起来

时间:2011-11-20 14:47:55

标签: java

我收到以下错误: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);
        }
    });

我不明白,因为根据我的代码,我正在定义方法。

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();
}

5 个答案:

答案 0 :(得分:1)

public void launchExternalBrowser(String url)

不同
public abstract void launchExternalBrowser();

为了满足类实现,您必须实现一个与抽象方法具有完全相同签名的函数。如果要将字符串作为参数传递,则必须定义抽象类中的方法。

答案 1 :(得分:1)

您正在实施public void launchExternalBrowser(String url) 而不是实施public void launchExternalBrowser() 区别在于方法的参数列表

答案 2 :(得分:0)

您忘记在string的抽象声明中包含launchExternalBrowser参数。

答案 3 :(得分:0)

使用一个参数覆盖该方法,而编译器似乎抱怨使用无参数的方法。也许你需要覆盖两者(或者只是没有任何参数的那个 - 取决于抽象类)。

答案 4 :(得分:0)

在MyWebViewClient中更改方法 launchExternalBrowser(),如下所示:

public void launchExternalBrowser(){

}