TextView的风格ArrayIndexOutOfBoundsException异常 [英] TextView styles ArrayIndexOutOfBoundsException

查看:348
本文介绍了TextView的风格ArrayIndexOutOfBoundsException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个经常性的死机从Play商店中我的管理控制台正在添加。我不明白为什么它的崩溃。
我从来没有重现此碰撞,它似乎是从三星Galaxy设备正在添加只(不那么肯定,虽然)。从SDK版本4.1&安培; 4.2&安培; 4.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

我想也许它是由我的风格给的TextView (特别是fontFamily中)引起的。因此,这里是从我的价值观-V16> styles.xml(值-V16)的样式:

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>

从值> styles.xml

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> 

在这里使用一个TextView的一个例子:

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 !

编辑:看来,它不仅在星系的设备,我也有这个崩溃了的Nexus 7

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

推荐答案

也许有可能是字体无衬线冷凝不可用在某些设备上的,这就是为什么该应用程序崩溃。如果你想支持更多的字体你可以把你的资产产生的文件夹,然后可以通过扩展TextView中创建一个CustomTextView

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);
}

}

和在你的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"
>

这篇关于TextView的风格ArrayIndexOutOfBoundsException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆