3

I have a recurrent crash comming in my admin console from the PlayStore. I can't see why it's crashing. I've never reproduce this crash, it's seems to be comming only from Samsung Galaxy device (not so sure though). From sdk version 4.1 & 4.2 & 4.3

Here is the full StackTrace :

android.view.InflateException: Binary XML file line #31: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.android.internal.widget.ActionBarContextView.initClose(ActionBarContextView.java:262)
at com.android.internal.widget.ActionBarContextView.onConfigurationChanged(ActionBarContextView.java:136)
at android.view.View.dispatchConfigurationChanged(View.java:7761)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1056)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1060)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1060)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1060)
at android.view.ViewGroup.dispatchConfigurationChanged(ViewGroup.java:1060)
at android.view.ViewRootImpl.updateConfiguration(ViewRootImpl.java:2800)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1509)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4464)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 31 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=24; index=691
at android.content.res.StringBlock.get(StringBlock.java:64)
at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:720)
at android.content.res.TypedArray.getString(TypedArray.java:124)
at android.widget.TextView.<init>(TextView.java:916)
at android.widget.TextView.<init>(TextView.java:562)
... 34 more

I was thinking maybe it's caused by the style I give to TextView (specially the fontFamily). So here is a style from my values-v16 > styles.xml (values-v16) :

 <style name="TextViewHour">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginLeft">5dip</item>
        <item name="android:ellipsize">end</item>
        <item name="android:maxLines">1</item>
        <item name="android:textSize">@dimen/text_hour_size</item>
        <item name="android:textColor">@color/item_hour</item>
        <item name="android:fontFamily">sans-serif-condensed</item>
        <item name="android:textStyle">bold</item>
    </style>

from values > styles.xml

 <style name="TextViewHour">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginLeft">5dip</item>
        <item name="android:ellipsize">end</item>
        <item name="android:maxLines">1</item>
        <item name="android:textSize">@dimen/text_hour_size</item>
        <item name="android:textColor">@color/item_hour</item>
        <item name="android:textStyle">bold</item>
    </style> 

here an example of use of a TextView :

<TextView
    style="@style/TextViewHour"
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/item_date_separator"/>

I don't have any clue on why my app is crashing on some devices. So if someone have an idea, I'm all ears !

EDIT : It seems that it's not only on galaxy devices, I also have this crash for Nexus 7.

Andros
  • 4,069
  • 1
  • 22
  • 30
  • I am also seeing a couple of crashes for this in my prod app. I downloaded the roboto fonts and am loading them into the app, but I forgot to remove "fontFamily" from some of my styles. I removed them now and will push the apk soon and will let you know if the crashes stop. – clocksmith Aug 06 '14 at 14:14

3 Answers3

5

I was experiencing the same crash until I removed android:fontFamily from my theme. I noticed you have android:fontFamily in your TextView.

copolii
  • 14,208
  • 10
  • 51
  • 80
3

It may possible that the font sans-serif-condensed is not available on some of devices, thats why the app is crashing. If you want to support additional font you can put that in your assests folder and then can create a CustomTextView by extending TextView

public class MyTextView extends TextView {

public MyTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
}

public MyTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public MyTextView(Context context) {
    super(context);
    init();
}

private void init() {
    Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
                                           "your_font.ttf");
    setTypeface(tf);
}

}

and in your xml.

<com.mypackage.test.MyTextView
 android:id="@+id/txt"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:gravity="center"
 android:layout_weight="1"
 android:text="custom text view. "
 android:textSize="30dip"
 android:textColor="#ff0000"
>
Avtar Guleria
  • 2,126
  • 3
  • 21
  • 33
  • the roboto fonts aren't available by defaults in all android 4.1 + versions ? I mean, obviously I'm not the only one using "font:family" in styles.xml. – Andros Jan 08 '14 at 13:39
  • It may not, so the safer approach is if you are willing to provide some particular font/fonts put the same in application bundle and use this like above. – Avtar Guleria Jan 08 '14 at 13:42
  • please have look on this..http://stackoverflow.com/questions/19113420/roboto-font-for-android-4 – Avtar Guleria Jan 08 '14 at 13:48
  • Also if you want to download roboto font you can download it from here. http://developer.android.com/design/style/typography.html – Avtar Guleria Jan 08 '14 at 13:48
  • Yes, well in the answer of the post it's written : "You can use Roboto natively from Android 4.1+ like this". And that's what I'm doing. – Andros Jan 08 '14 at 13:53
0

My app experienced a similar InflateException and Googling led me to this thread.

For me, the code causing my TextView to raise the exception was this:

android:textAlignment="viewStart"

Reworking my layout so this entry was not necessary fixed my issue.

Chris Lacy
  • 4,222
  • 3
  • 35
  • 33