Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error inflating xml layout ArrayIndexOutOfBoundsException on TextView

I ran into a weird crash problem. I can't quite seem to figure out the problem.

Here is the crash report.

                  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) 

Here is my activity xml file.

<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>

As the crash report says the error seems to be on line 125 which is a TextView and if I remove the text view error happens on its sibling TextView.

Any notion or help would be highly appreciated!

UPDATE I was able to narrow it down to one attribute which is causing the problem,

android:textAllCaps="true"

Any idea why making text all caps gives this exception?

like image 297
Samuel Robert Avatar asked Mar 20 '17 13:03

Samuel Robert


3 Answers

In my case I had android:textDirection="firstStrongLtr" and firstStrongLtr was causing the crash, although the compiler was fine with it. so I changed it to ltr and everything was good. so the answer is to also avoid using firstStrongLtr and firstStrongRtl

like image 63
Bassel Mourjan Avatar answered Sep 20 '22 13:09

Bassel Mourjan


use Button or .setTransformationMethod(new AllCapsTransformationMethod(getContext()))

like image 33
Reven Avatar answered Sep 21 '22 13:09

Reven


This can be fixed by calling setAllCaps(true) on the TextView/Button. If you're using databinding that's simply custom_ns:allCaps="@{true}" in XML.

like image 37
ubuntudroid Avatar answered Sep 21 '22 13:09

ubuntudroid