5

Background

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.

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

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 .

The problem

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)

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.

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?

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • How different is your layout from the [canonical nav drawer layout for AppCompat v21](http://stackoverflow.com/a/26440880/1676363) as posted by the creator of AppCompat? Do you actually call `findViewById(android.R.id.content).setLayoutParams()` anywhere in your app? – ianhanniballake Oct 26 '14 at 20:42
  • It's different by that I don't have the toolbar behind the navigation drawer. Anyway, I've posted a shorted version of the layout XML I use. But why the downvote of the question? At least provide an explanation of the reason... – android developer Oct 26 '14 at 22:01
  • So the Github issue you linked to said the person *removed* those lines from their app (rather than adding anything) so I'd look to see if you are doing something similar anywhere, but your XML looks well enough (if not actually matching the design guidelines for the side nav). (Note: I didn't downvote) – ianhanniballake Oct 26 '14 at 23:42
  • I see. so I don't know what to do... Maybe I could try to set a toolbar as the actionbar ? – android developer Oct 27 '14 at 06:18
  • Trying it with that known good layout might help narrow down if it is something odd in your XML or a code problem – ianhanniballake Oct 27 '14 at 06:24
  • @ianhanniballake I don't understand. You mean I should try what I've written? – android developer Oct 27 '14 at 08:52
  • No, try what Chris Banes wrote in the question I linked: that layout *does* work. – ianhanniballake Oct 27 '14 at 13:48
  • @ianhanniballake He has a toolbar too... He just set the hierarchy differently . – android developer Oct 27 '14 at 15:27
  • Do you try to programmatically change any Toolbar views like the title color? "getIdentifier("action_bar_title", "id", "android")" bombs out on kitkat... If this is your case, replace this with a SpannableString and setText. 4x+ accepts SpannableString (which can include color) in the setText. – Codeversed Nov 26 '14 at 06:28
  • @Codeversed No , I don't. Anyway, I've decided to use the new Toolbar class, so this might solve everything... Thanks anyway. – android developer Nov 26 '14 at 09:04
  • I have the same problem. Did you found the solution ? – Behrouz.M Nov 09 '15 at 08:40

1 Answers1

12

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.

robUx4
  • 853
  • 9
  • 13
  • I don't understand. So what should I do? And how come all other devices can handle it just fine? – android developer Oct 31 '14 at 09:28
  • If you remove one of them in your theme it will work. Most of the time you don't even need them anyway because AppCompat handles that stuff for you. – robUx4 Oct 31 '14 at 09:29
  • 1
    I didn't have any of them on the app that's published on the Play store. So what should be the solution? Only now I've thought of adding them, creating a Toolbar, and setting it as the actionBar, using setSupportActionBar . – android developer Oct 31 '14 at 11:06
  • Worked for me (using AppCompat, targetSDK v23, testing on API 19) Removed those two lines, sued the newer Activity (AppCompatActivity iirc), and presto, it worked – DragonJawad Apr 11 '16 at 15:53