我在PlayStore的管理控制台中经常出现崩溃.我不明白为什么它会崩溃. 我从来没有重现过这次崩溃,它似乎只是来自三星Galaxy设备(虽然不太确定).来自sdk 4.1版 4.2 4.3 这是完整的StackTrace:
我从来没有重现过这次崩溃,它似乎只是来自三星Galaxy设备(虽然不太确定).来自sdk 4.1版& 4.2& 4.3
这是完整的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(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
<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的例子:
<TextView style="@style/TextViewHour" android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/item_date_separator"/>
我对我的应用程序在某些设备上崩溃的原因一无所知.
所以,如果有人有想法,我全都耳朵!
编辑:似乎它不仅在Galaxy设备上,我也有这个Nexus 7的崩溃.
字体sans-serif-condensed可能在某些设备上不可用,这就是应用程序崩溃的原因.如果要支持其他字体,可以将其放在assests文件夹中,然后通过扩展TextView创建CustomTextViewpublic 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" >