faboptions icon indicating copy to clipboard operation
faboptions copied to clipboard

Exception android.widget.ImageView cannot be cast to android.support.v7.widget.AppCompatImageView

Open alexdrottsgard opened this issue 6 years ago • 7 comments

I've been trying to implement your Floating Action Button. I've followed the instructions you've made. When I try to run my app I get: Caused by: java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.support.v7.widget.AppCompatImageView

I'm not sure if it's something on my side, or on the main source code. The error is pointing at line 52 in your FabOptionsContainer.

Thanks in advance!

alexdrottsgard avatar Oct 24 '18 09:10 alexdrottsgard

Hey @alexdrottsgard Have you tried to clean your project and build again?

JoaquimLey avatar Oct 24 '18 09:10 JoaquimLey

Yeah I have..

alexdrottsgard avatar Oct 24 '18 09:10 alexdrottsgard

This shows a missing library if you read the error message carefully. Also, I would need a little more context/code to understand what might be happening, which version are you importing from gradle?

JoaquimLey avatar Oct 25 '18 21:10 JoaquimLey

Yeah sorry! I have a Google Map Activity, on which I put your FAB. I've made the menu xml and I put it programmatically in my MapsActivity. My layout is a FrameLayout, which has the map fragment and the FAB.

How I make my menu item:

<item
        android:id="@+id/first_item"
        android:icon="@drawable/my_image"
        android:title="First Item" />

I have also tried to do:

<item
        android:id="@+id/first_item"
        app:srcCompat="@drawable/my_image"
        android:title="First Item" />

My onCreate, where I put the menu to the FAB:

fabOptions = findViewById(R.id.fab);
fabOptions.setButtonsMenu(R.menu.fab_menu);

Version in my gradle:

implementation 'com.github.joaquimley:faboptions:1.2.0'

alexdrottsgard avatar Oct 26 '18 09:10 alexdrottsgard

Can you provide the list of your other dependencies?

JoaquimLey avatar Dec 13 '18 13:12 JoaquimLey

@alexdrottsgard I think issue is here:

<item
        android:id="@+id/first_item"
        app:srcCompat="@drawable/my_image"
        android:title="First Item" />

you are using srcCompat and this is causing the issue in Casting from normal image to srcCompat image

abduldblogger avatar Dec 13 '18 13:12 abduldblogger

Oh I haven't tested with srcCompat in the menu, I'm not sure if it works tbh. But can't you use the same as the sample?

  • https://github.com/JoaquimLey/faboptions/blob/development/sample/src/main/res/menu/menu_faboptions.xml

JoaquimLey avatar Jan 22 '19 12:01 JoaquimLey