2011-11-20 69 views
1

,我发现了以下错误: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(); 
} 

回答

1
public void launchExternalBrowser(String url) 

是不一样的

public abstract void launchExternalBrowser(); 

为了满足类的实现,必须实现具有完全相同的签名抽象方法的功能。如果你想传入一个字符串作为参数,你必须定义抽象类中的方法。

0

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

0

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

1

要实现public void launchExternalBrowser(String url) ,而不是实施public void launchExternalBrowser() 的区别是在方法

0

更改方法launchExternalBrowser()像这里面MyWebViewClient像这样的参数列表:

public void launchExternalBrowser(){ 

}