6 votes

Erreur de gonflage de la disposition xml ArrayIndexOutOfBoundsException sur TextView

J'ai rencontré un étrange problème de plantage. Je n'arrive pas à comprendre le problème.

Voici le rapport d'accident.

                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bigappcompany.grocery/com.bigappcompany.grocery.activity.OrderDetailsActivity}: android.view.InflateException: Binary XML file line #125: Binary XML file line #125: Error inflating class <unknown>
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2560)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626)
                  at android.app.ActivityThread.-wrap11(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
                  at android.os.Handler.dispatchMessage(Handler.java:111)
                  at android.os.Looper.loop(Looper.java:207)
                  at android.app.ActivityThread.main(ActivityThread.java:5740)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766)
               Caused by: android.view.InflateException: Binary XML file line #125: Binary XML file line #125: Error inflating class <unknown>
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                  at com.bigappcompany.grocery.activity.OrderDetailsActivity.onCreate(OrderDetailsActivity.java:11)
                  at android.app.Activity.performCreate(Activity.java:6543)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475) 
                  at android.os.Handler.dispatchMessage(Handler.java:111) 
                  at android.os.Looper.loop(Looper.java:207) 
                  at android.app.ActivityThread.main(ActivityThread.java:5740) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766) 
               Caused by: android.view.InflateException: Binary XML file line #125: Error inflating class <unknown>
                  at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                  at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                  at com.bigappcompany.grocery.activity.OrderDetailsActivity.onCreate(OrderDetailsActivity.java:11) 
                  at android.app.Activity.performCreate(Activity.java:6543) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475) 
                  at android.os.Handler.dispatchMessage(Handler.java:111) 
                  at android.os.Looper.loop(Looper.java:207) 
                  at android.app.ActivityThread.main(ActivityThread.java:5740) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766) 
               Caused by: java.lang.reflect.InvocationTargetException
                  at java.lang.reflect.Constructor.newInstance(Native Method)
                  at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                  at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                  at com.bigappcompany.grocery.activity.OrderDetailsActivity.onCreate(OrderDetailsActivity.java:11) 
                  at android.app.Activity.performCreate(Activity.java:6543) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475) 
                  at android.os.Handler.dispatchMessage(Handler.java:111) 
                  at android.os.Looper.loop(Looper.java:207) 
                  at android.app.ActivityThread.main(ActivityThread.java:5740) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766) 
               Caused by: java.lang.ArrayIndexOutOfBoundsException: length=38; index=384
                  at android.content.res.StringBlock.get(StringBlock.java:65)
                  at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
                  at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:1151)
                  at android.content.res.TypedArray.getString(TypedArray.java:195)
                  at android.widget.TextView.<init>(TextView.java:1091)
                  at android.widget.TextView.<init>(TextView.java:696)
                  at android.widget.TextView.<init>(TextView.java:692)
                  at java.lang.reflect.Constructor.newInstance(Native Method) 
                  at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                  at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                  at com.bigappcompany.grocery.activity.OrderDetailsActivity.onCreate(OrderDetailsActivity.java:11) 
                  at android.app.Activity.performCreate(Activity.java:6543) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475) 
                  at android.os.Handler.dispatchMessage(Handler.java:111) 
                  at android.os.Looper.loop(Looper.java:207) 
                  at android.app.ActivityThread.main(ActivityThread.java:5740) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766) 

Voici mon fichier xml d'activité.

<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"
tools:context="com.bigappcompany.grocery.activity.OrderDetailsActivity">

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:paddingBottom="@dimen/narrow"
        android:paddingEnd="@dimen/medium"
        android:paddingStart="@dimen/medium"
        android:paddingTop="@dimen/narrow"
        android:text="@string/order_summary"
        android:textSize="@dimen/text_medium"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/narrow"
        android:background="@color/white"
        android:paddingEnd="@dimen/medium"
        android:paddingStart="@dimen/large"
        android:paddingTop="@dimen/standard">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/order_number"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="end"
            android:text="#123123"
            android:textColor="@color/black"
            android:textStyle="bold"/>
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginEnd="@dimen/narrow"
        android:layout_marginStart="@dimen/narrow"
        android:layout_marginTop="@dimen/thin"
        android:background="@color/colorBackground"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_order"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="@dimen/thin"
        android:layout_weight="1"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/narrow"
        android:background="@color/white"
        android:orientation="vertical"
        android:padding="@dimen/standard">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/cart_estimated"/>

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="end"
                android:text="95"
                android:textColor="@color/colorPrimary"
                android:textStyle="bold"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/narrow"
            android:background="@color/white">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/order_status"/>

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="end"
                android:text="shipped"
                android:textColor="@color/black"
                android:textStyle="bold"/>
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:orientation="horizontal"
        android:padding="@dimen/standard">

        <!-- line #125--> <TextView 
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/call_us"
            android:textAllCaps="true"
            android:textColor="@color/white"
            android:textSize="@dimen/text_big"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/email_us"
            android:textAllCaps="true"
            android:textColor="@color/white"
            android:textSize="@dimen/text_big"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/Cancel"
            android:textAllCaps="true"
            android:textColor="@color/transparent_White"
            android:textSize="@dimen/text_big"/>
    </LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

Comme le dit le rapport de crash, l'erreur semble se situer sur la ligne 125 qui est un TextView et si je supprime le TextView, l'erreur se produit sur son TextView frère.

Toute idée ou aide serait très appréciée !

MISE À JOUR J'ai pu réduire le problème à un seul attribut,

android:textAllCaps="true"

Savez-vous pourquoi le fait de mettre le texte en majuscules donne lieu à cette exception ?

2voto

Bassel Mourjan Points 111

Dans mon cas, j'avais android:textDirection="firstStrongLtr" y firstStrongLtr provoquait le crash, bien que le compilateur s'en accommodait. je l'ai donc remplacé par ltr et tout s'est bien passé. la réponse est donc d'éviter également d'utiliser des firstStrongLtr y firstStrongRtl

1voto

Reven Points 121

Utiliser le bouton ou .setTransformationMethod(new AllCapsTransformationMethod(getContext()))

1voto

ubuntudroid Points 718

Ce problème peut être résolu en appelant setAllCaps(true) sur le TextView/Button. Si vous utilisez la liaison de données, c'est simplement custom_ns:allCaps="@{true}" en XML.

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X