其他分享
首页 > 其他分享> > android-由于支持ActionBar的类强制转换异常而无法启动活动

android-由于支持ActionBar的类强制转换异常而无法启动活动

作者:互联网

从一个android.support.v7.app.ActionBarActivity开始,我正在启动另一个android.support.v7.app.ActionBarActivity活动,但得到了以下异常:

FATAL EXCEPTION: main
    Process: com.playgong.stg.dbg, PID: 32299
    java.lang.ClassCastException: android.support.v7.internal.widget.ActionBarOverlayLayout$LayoutParams cannot be cast to com.android.internal.widget.ActionBarOverlayLayout$LayoutParams
            at com.android.internal.widget.ActionBarOverlayLayout.applyInsets(ActionBarOverlayLayout.java:172)
            at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:317)
            at android.view.View.measure(View.java:16497)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
            at android.view.View.measure(View.java:16497)
            at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
            at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
            at android.view.Choreographer.doCallbacks(Choreographer.java:574)
            at android.view.Choreographer.doFrame(Choreographer.java:544)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)

第一次活动有风格

<style name="PS" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>

    <item name="android:windowContentTransitions">true</item>
</style>

第二(崩溃的):

<style name="PS.Second" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/PS.ActionBar</item>

    <item name="android:windowNoTitle">false</item>
    <item name="android:windowActionBar">true</item>
</style>

任何想法如何避免ClassCastException?

解决方法:

我不确定什么是PS.ActionBar样式.所以我把它注释掉了.并在Device Moto G API 21上尝试了相同的操作.我看不到崩溃.

话虽如此,这次崩溃似乎是内部的.除了不推荐使用ActionBarActivity之外,还可以使用AppCompatActivity.

PS:我仍在等待您的答案,因此我可以使用更多发现来编辑答案.

标签:classcastexception,android-styles,android-actionbar,android
来源: https://codeday.me/bug/20191120/2046893.html