java.lang.ClassCastException:android.support.v7.widget.ActivityChooserView $ InnerLayout无法转换为android.support.v7.widget.LinearLayoutCompat [英] java.lang.ClassCastException: android.support.v7.widget.ActivityChooserView$InnerLayout cannot be cast to android.support.v7.widget.LinearLayoutCompat
问题描述
从LinearLayout切换到ConstraintLayout会引发此错误
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
当我尝试在片段中的onCreateOptionsMenu()
中添加菜单时发生错误.
The error occurs when i try to inflate the menu in onCreateOptionsMenu()
in my fragment.
我要膨胀的菜单:-
<?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>
我的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:-
更新:-添加app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
项会导致错误.
Update :- Adding the app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
item causes the error.
如ShaneCoder所建议的那样,下拉至27.0.2
/更改为LinearLayout
可以消除错误,但我想知道
As suggested by ShaneCoder dropping down to 27.0.2
/ changing to LinearLayout
removes the error but i want to know
为什么
27.1.0
在夸大Classandroid.support.v7.widget.ShareActionProvider
时在运行时抛出此类错误? (这是27.1.0
中的错误)
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
)
推荐答案
不确定这是否是您要解决的问题...
Not sure if this is the issue you're fighting ...
我最近升级了我的支持库依赖项.使用支持库27.1.0
,我得到了经过验证的代码的异常.我现在正在使用27.0.2
.这个异常消失了.
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.
修改
我不确定27.1.0
怎么了.过去,我不得不备份次要版本,以解决从升级到最新支持库的问题.我猜没有人是完美的.我相信27.0.2
是27.1.0
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
编辑2
此处是指向Googles Issue Tracker上该问题的链接.标记为固定的2018年2月28日.应尽快发布.
Here's a link to the issue on Googles Issue Tracker. It's marked fixed February 28, 2018. Should be released soon.
编辑3
已确认在27.1.1
这篇关于java.lang.ClassCastException:android.support.v7.widget.ActivityChooserView $ InnerLayout无法转换为android.support.v7.widget.LinearLayoutCompat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!