delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

Cannot cast my MainActivity into Advanced Webview Listener #304

Closed RawPlutonium closed 2 years ago

RawPlutonium commented 2 years ago

Error

022-02-26 15:12:43.683 13941-13941/com.example.paamemregistration E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.paamemregistration, PID: 13941 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.paamemregistration/com.example.paamemregistration.MainActivity}: java.lang.ClassCastException: com.example.paamemregistration.MainActivity cannot be cast to im.delight.android.webview.AdvancedWebView$Listener at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3108) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3251) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7045) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) Caused by: java.lang.ClassCastException: com.example.paamemregistration.MainActivity cannot be cast to im.delight.android.webview.AdvancedWebView$Listener at com.example.paamemregistration.MainActivity.onCreate(MainActivity.java:19) at android.app.Activity.performCreate(Activity.java:7327) at android.app.Activity.performCreate(Activity.java:7318) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3088) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3251)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:214)  at android.app.ActivityThread.main(ActivityThread.java:7045)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 

Code

        super.onCreate(savedInstanceState);
        mWebView = (AdvancedWebView) findViewById(R.id.webView);
        mWebView.setListener(this, (AdvancedWebView.Listener) this);
        mWebView.setMixedContentAllowed(false);
        mWebView.loadUrl("https://someurl.com");

Kindly assist. It seems to be grabbing the webview fine but is unable to set the listener. when I try with mWebView.setListener(this, this);it brings an error for me to specify that the listener for the second context is Advanced Webview Listener.

ocram commented 2 years ago

You might have forgotten implements AdvancedWebView.Listener at the top of your MainActivity, and then implementing what this interface requires.

RawPlutonium commented 2 years ago

Hello. That works fine. Thanks