java - MainActivity 不是抽象的,不会重写 Listener 中的抽象方法 onPageStarted(String,Bitmap)

标签 java android

我正在尝试显示一个带有 AdvancedWebView 的 html 文件成分。但问题是,它显示了该行的错误

public class MainActivity extends Activity implements AdvancedWebView.Listener {

错误提示,

Error:(18, 8) error: MainActivity is not abstract and does not override abstract method onPageStarted(String,Bitmap) in Listener

这是我的 MainActivity.java 文件。

package com.test.test3;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import im.delight.android.webview.AdvancedWebView;

public class MainActivity extends Activity implements AdvancedWebView.Listener {
    private AdvancedWebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = (AdvancedWebView) findViewById(R.id.webview);
        mWebView.setListener(this, this);
        mWebView.setGeolocationEnabled(false);
        mWebView.setMixedContentAllowed(true);
        mWebView.setCookiesEnabled(true);
        mWebView.setThirdPartyCookiesEnabled(true);

        mWebView.addHttpHeader("X-Requested-With", "");
        mWebView.loadUrl("file:///android_asset/index.html");
    }
}

我在这里做错或遗漏了什么?

最佳答案

如果您通过类实现接口(interface)并且该类不是抽象的,则必须重写所有接口(interface)方法。

您的MainActivity实现了this interface :

public interface Listener {
        void onPageStarted(String url, Bitmap favicon);
        void onPageFinished(String url);
        void onPageError(int errorCode, String description, String failingUrl);
        void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent);
        void onExternalPageRequest(String url);
    }

但不会覆盖它的方法。

您需要覆盖所有 AdvancedWebView.Listener方法:onPageStartedonPageFinishedonPageErroronDownloadRequestedonExternalPageRequest

关于java - MainActivity 不是抽象的,不会重写 Listener 中的抽象方法 onPageStarted(String,Bitmap),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50099221/

相关文章:

java - Android:将 AppWidgetId 传递给服务

java - Selenium - 多浏览器和多用户登录

java - 在不使用 java 递归的情况下,为给定输入节点在二叉树中打印祖先节点

android - 如何在 opengl 2.0 中的对象上绘制线框?

java - 使用hadoop作业的输出作为另一个的输入

java - 动态 Log4j2 日志文件路径

java - ImageButton 图像调整大小

android - Android应用程序中的深度链接

android - Whatsapp 联系人同步

android - 无法让操作栏中的搜索 View 工作