ClassCastException异常的支持库-V7,使用的版本21 [英] ClassCastException on support-library-v7 , using version 21

查看:262
本文介绍了ClassCastException异常的支持库-V7,使用的版本21的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的2个星期,我一直在动我的应用程序从ActionBarSherlock到谷歌的官方支持库,也收获了材料,设计风格。

Over the past 2 weeks I've been moving my app from ActionBarSherlock to the official support library of Google, to also gain Material-Design style.

我已经更新到最新的一(即21),而我既包括v4和它V7。

I've updated to the newest one (which is 21), and I've included both v4 and v7 of it.

我的应用程序 有一个简单的导航抽屉,一个操作杆,和一个片段容器的碎片(我只有2)之间切换。屏幕的其余部分是设置屏幕,快捷键操作系统的工具。我也有一个小部件配置屏幕,但是这无关紧要。

My app has a simple navigation-drawer , an action-bar, and a fragment container to switch between the fragments (which I only have 2). The rest of the screens are the settings screen and shortcuts to OS's tools. I also have a widget-configuration screen, but that's irrelevant .

我从声称它崩溃每次上LG-G2,采用Android 4.4用户的崩溃:

I got a crash from a user that claims it crashes every time, on LG-G2, with Android 4.4 :

java.lang.ClassCastException: android.support.v7.internal.widget.m 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:16538)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5140)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2374)
at android.view.View.measure(View.java:16538)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1964)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1160)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1342)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1047)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5896)
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:5105)
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:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)

的XML我用

下面是一个简短的版本,我使用的布局XML的:

The XML I use

Here's a short version of the XML I use for the layout:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/activity_app_list__drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <FrameLayout
                android:id="@+id/activity_app_list__fragmentContainer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/activity_app_list__adContainer"
                android:layout_alignParentTop="true" />

            <FrameLayout
                android:id="@+id/activity_app_list__adContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true" />
        </RelativeLayout>

        <ScrollView
            android:id="@+id/activity_app_list__drawerView"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="?android:attr/windowBackground" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <==just some views for the drawer...
            </LinearLayout>
        </ScrollView>

    </android.support.v4.widget.DrawerLayout>

我发现什么

我在网上搜索,发现几乎没有谈到这个问题。

What I've found

I've searched the Internet, and found almost nothing about this problem.

我发现的唯一一件事就是 这个帖子 ,但他们不知道如何以及为什么会发生。另外,我甚至不使用这个库,我不知道这是同样的错误。尖端有删除的下一个code:

The only thing I've found is this post, but they don't tell how and why it happens. Plus I don't even use this library, and I'm not sure it's the same error. The tip there was to remove the next code:

(ViewGroup)findViewById(android.R.id.content).setLayoutParams(new LinearLayout.LayoutParams(-1, -1));

问题

为什么会出现这种问题?我该如何解决这个问题?

The question

Why does it occur? How can I fix it?

将使用尖端的职位帮助?

Will using the tip on the post help?

推荐答案

我有同样的问题,找到了罪魁祸首。这是当你有你的 AppCompat 主题这2个因素:

I had the same problem and found the culprit. It's when you have these 2 elements in your AppCompat theme:

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

崩溃似乎只发生在奇巧。

The crash only seems to occur on KitKat.

这篇关于ClassCastException异常的支持库-V7,使用的版本21的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆