Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassCastException: android.support.v7.widget.ActivityChooserView$InnerLayout cannot be cast to android.support.v7.widget.LinearLayoutCompat

Switching from LinearLayout to ConstraintLayout throwing this error

java.lang.ClassCastException: android.support.v7.widget.ActivityChooserView$InnerLayout cannot be cast to android.support.v7.widget.LinearLayoutCompat                                                                                                                                             

The error occurs when i try to inflate the menu in onCreateOptionsMenu() in my fragment.

My menu which I inflate :-

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">   
    <item
        android:id="@+id/action_share"
        app:showAsAction="always"
        android:orderInCategory="101"
        android:icon="@android:drawable/ic_menu_share"
        android:title="@string/action_share"
        app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
        />
</menu>

My onCreateOptionsMenu(..)

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {     
    inflater.inflate(R.menu.customerdetail, menu);      
    MenuItem menuItem = menu.findItem(R.id.action_share);
    mShareActionProvider = (ShareActionProvider) 
    MenuItemCompat.getActionProvider(menuItem);         
 // If i comment out this whole part everything is fine !!
 }

Edit :- ScreenShot of the log:-

enter image description here

Update :- Adding the app:actionProviderClass="android.support.v7.widget.ShareActionProvider" item causes the error.

As suggested by ShaneCoder dropping down to 27.0.2 / changing to LinearLayout removes the error but i want to know

Why is 27.1.0 is throwing such error at runtime while inflating Class,android.support.v7.widget.ShareActionProvider ? (is it a bug in 27.1.0 )

like image 463
Santanu Sur Avatar asked Mar 08 '18 13:03

Santanu Sur


1 Answers

Not sure if this is the issue you're fighting ...

I recently upgraded my support library dependencies. With support libraries 27.1.0 I was getting this exception with proven code. I'm using 27.0.2 now. This exception is gone.

Not tested or proven, but thought it might help.

Edit

I'm not sure what is wrong with 27.1.0. I've had to back up a minor release in the past to resolve from upgrading to the latest support libraries. I guess nobody's perfect. I believe 27.0.2 is the latest release prior to 27.1.0

Edit 2

Here's a link to the issue on Googles Issue Tracker. It's marked fixed February 28, 2018. Should be released soon.

Edit 3

Confirmed fixed in 27.1.1

like image 172
ShaneCoder Avatar answered Oct 07 '22 07:10

ShaneCoder