1

我在某些设备上遇到了这个异常,我不知道是什么原因造成的。

java.util.ArrayList.throwIndexOutOfBoundsException (ArrayList.java:255)
java.util.ArrayList.get (ArrayList.java:308)
android.support.design.widget.CoordinatorLayout.onChildViewsChanged (CoordinatorLayout.java:1225)  android.support.design.widget.CoordinatorLayout$HierarchyChangeListener.onChildViewRemoved (CoordinatorLayout.java:2863)
android.view.ViewGroup.dispatchViewRemoved (ViewGroup.java:4226)
android.view.ViewGroup.removeViewInternal (ViewGroup.java:4627)
android.view.ViewGroup.removeViewInternal (ViewGroup.java:4582)
android.view.ViewGroup.removeView (ViewGroup.java:4513)
android.support.design.widget.Snackbar.onViewHidden (Snackbar.java:646)
android.support.design.widget.Snackbar.access$300 (Snackbar.java:72)
android.support.design.widget.Snackbar$9.onAnimationEnd (Snackbar.java:588)
android.support.v4.view.ViewPropertyAnimatorCompatJB$1.onAnimationEnd (ViewPropertyAnimatorCompatJB.java:47)
android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd (ViewPropertyAnimator.java:1114)
android.animation.ValueAnimator.endAnimation (ValueAnimator.java:1239)
android.animation.ValueAnimator$AnimationHandler.doAnimationFrame (ValueAnimator.java:766)
android.animation.ValueAnimator$AnimationHandler$1.run (ValueAnimator.java:801)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:873)
android.view.Choreographer.doCallbacks (Choreographer.java:676)
android.view.Choreographer.doFrame (Choreographer.java:603)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:859)
android.os.Handler.handleCallback (Handler.java:739)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:168)
android.app.ActivityThread.main (ActivityThread.java:5845)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:797)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:687)

我有一个 activity_main xml 文件,其中包含一个 app_bar_main.xml,其中包含一个 content_mail xml 文件。

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

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

app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/bar_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".application.activities.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".application.activities.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.design.widget.CoordinatorLayout>

我正在标准内容视图上制作小吃栏,但由于异常,它几乎在随机时刻崩溃。奇怪的是,在我自己的设备/模拟器上,我无法重现错误(虽然我能够先重现它,但我将 Snackbar 的视图更改为 android.R.id.content 然后它停止出现在我的设备上) . 但在其他设备上,例如我朋友的 HTC M8(Android 6.0),确实出现了异常。

 Snackbar.make(findViewById(android.R.id.content), "Updating " + info.type, Snackbar.LENGTH_LONG).show();

更新 1:发现了类似的问题

4

1 回答 1

0

我通过降级到较旧的 Android 支持库版本 (v24.1.1) 解决了我的问题。在此处查看 Android 问题跟踪器。

更新 1 似乎它将在下一个版本的 Android 支持库(v24.2.1)中得到解决

UPDATE 2 24.2.1 已于今天发布,错误似乎已解决。至少我无法用当前版本重现它。– PattaFeuFeu

于 2016-09-07T15:52:13.810 回答