无效的void错误和非法修饰符错误

时间:2013-08-05 21:13:11

标签: void modifier

我一直收到这个错误:

  

本地类myWebClient的非法修饰符;只允许抽象或最终。

并出现此错误:

  

void是变量backButtonClicked的无效类型

发生错误的代码。

public class myWebClient extends WebViewClient
{

}
public void backButtonClicked(View view)
{
    if (ourBrow.canGoBack())
    ourBrow.goBack();
}

public void forwardButtonClicked(View view)
{
    if (ourBrow.canGoForward())
    ourBrow.goForward();
}

public void goButtonClicked(View view)
{
    String theWebsite = Url.getText().toString();
    if(theWebsite != null)
    ourBrow.loadUrl(theWebsite);
}

public void refreshButtonClicked(View view)
{
    ourBrow.reload();
}

1 个答案:

答案 0 :(得分:1)

删除类的public修饰符,并将所有方法放在类的主体中:

class myWebClient extends WebViewClient
{

    public void backButtonClicked(View view)
    {
        if (ourBrow.canGoBack())
        ourBrow.goBack();
    }

    public void forwardButtonClicked(View view)
    {
        if (ourBrow.canGoForward())
        ourBrow.goForward();
    }

    public void goButtonClicked(View view)
    {
        String theWebsite = Url.getText().toString();
        if(theWebsite != null)
        ourBrow.loadUrl(theWebsite);
    }

    public void refreshButtonClicked(View view)
    {
        ourBrow.reload();
    }
}