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

Problem to cast the AdvancedWebView #30

Closed BoFoPinttag closed 8 years ago

BoFoPinttag commented 8 years ago

I have so many issues with the openFileChooser because im using a webview so. I decided to use your AdvaneWebView and im having this problem with the cast of the webview. I would apreciate if you could help me with this issue. Thanks

ERROR:

7954-7954/? E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.pinttag.pinttag, PID: 7954 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pinttag.pinttag/com.pinttag.pinttag.MainActivity}: java.lang.ClassCastException: im.delight.android.webview.AdvancedWebView cannot be cast to com.pinttag.pinttag.AdvancedWebView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2790) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855) at android.app.ActivityThread.access$900(ActivityThread.java:181) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6117) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: java.lang.ClassCastException: im.delight.android.webview.AdvancedWebView cannot be cast to com.pinttag.pinttag.AdvancedWebView at com.pinttag.pinttag.MainActivity.onCreate(MainActivity.java:53) at android.app.Activity.performCreate(Activity.java:6374) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2743)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)             at android.app.ActivityThread.access$900(ActivityThread.java:181)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:145)             at android.app.ActivityThread.main(ActivityThread.java:6117)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java:372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

Main_Activity:

import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle;

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.loadUrl("http://www.pinttag.com");

    // ...
}

@SuppressLint("NewApi")
@Override
protected void onResume() {
    super.onResume();
    mWebView.onResume();
    // ...
}

@SuppressLint("NewApi")
@Override
protected void onPause() {
    mWebView.onPause();
    // ...
    super.onPause();
}

@Override
protected void onDestroy() {
    mWebView.onDestroy();
    // ...
    super.onDestroy();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    mWebView.onActivityResult(requestCode, resultCode, intent);
    // ...
}

@Override
public void onBackPressed() {
    if (!mWebView.onBackPressed()) { return; }
    // ...
    super.onBackPressed();
}

@Override
public void onPageStarted(String url, Bitmap favicon) { }

@Override
public void onPageFinished(String url) { }

@Override
public void onPageError(int errorCode, String description, String failingUrl) { }

@Override
public void onDownloadRequested(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { }

@Override
public void onExternalPageRequest(String url) { }

}

LAYOUT

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="0dp" android:paddingRight="0dp" android:paddingTop="0dp" android:paddingBottom="0dp" tools:context=".MainActivity">

<im.delight.android.webview.AdvancedWebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

ocram commented 8 years ago

Thanks for your question!

The following line says it all:

java.lang.ClassCastException: im.delight.android.webview.AdvancedWebView cannot be cast to com.pinttag.pinttag.AdvancedWebView

So it seems you have a class named AdvancedWebView in your own package com.pinttag.pinttag as well. Please remove that class if it's only a copy of the library, since you seem to have the copy in the correct package ´im.delight.android.webview` as well (or included the JAR).

Afterwards, you'll probably need to fix some imports.