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:-
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 in27.1.0
)
linear Layouts
even in the fragments..!! @Redman – SulfuricBody is limited to 30000 characters; you entered 31914.
@cricket_007 and i wrapped another constraint layout in because i could not givepaddingbottom
to the immediate child of theScrollView
– Sulfuricexcept the classCastException
)...i searched but found none with this error !! @cricket_007 – Sulfuricat ToolbarActionBar.populateOptionMenu
... Unless you're loading this layout into a Toolbar or a Share action, I don't think the ConstraintLayout is there problem. – CognaconCreateOptionsMenu(..)
( menu-contains a shareActionProvider ) inside the fragment then everything works fine. P.S this problem occurs after i switch to constraintLayout.. – Sulfuric