0

我有一个带有 Button 的布局:

<Button
    android:id="@+id/myapp_new"
    style="@style/header_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:background="@drawable/header_button"
    android:gravity="center"
    android:text="new" />

按钮的样式定义如下:

<style name="header_button" parent="@android:style/TextAppearance.Medium">
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">16sp</item>
</style>

当我在手机上打开此活动时,我收到了崩溃。崩溃发生在设置内容视图的行中:

setContentView(R.layout.layout_tags);

如果我删除android:background参数,崩溃就会消失。我不明白,因为 drawable 包含在应用程序中,并且它在其他设备上运行良好,包括模拟器。

我将在此线程的底部发布错误日志。

正如我所说,这种崩溃只发生在我的一台设备上(我有 2 个 + 模拟器)。它发生在运行 Android 2.2.1 的旧手机上,但没有出现在我的模拟器(运行 2.2)或我的新手机(运行 4.1.2)上。

最大的不同是我的崩溃设备的屏幕分辨率较低。我在 ldpi 文件夹中没有图像。我的印象是Android会自动从下一个文件夹中选择图像。此外,我还有很多其他加载得很好的图像。

我真的很想将我的应用程序发布到 Google Play 商店,但这阻碍了我。我担心这种崩溃会发生在其他人的手机上,即使我只能在一台设备上重现它。有没有人有任何想法?我迷路了。

11-26 12:03:04.740: E/AndroidRuntime(2800): FATAL EXCEPTION: main
11-26 12:03:04.740: E/AndroidRuntime(2800): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.app/com.myapp.app.activity.ActivityTags}: android.view.InflateException: Binary XML file line #65: Error inflating class android.widget.Button
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.os.Looper.loop(Looper.java:123)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at java.lang.reflect.Method.invokeNative(Native Method)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at java.lang.reflect.Method.invoke(Method.java:521)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at dalvik.system.NativeStart.main(Native Method)
11-26 12:03:04.740: E/AndroidRuntime(2800): Caused by: android.view.InflateException: Binary XML file line #65: Error inflating class android.widget.Button
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.app.Activity.setContentView(Activity.java:1647)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at com.myapp.app.activity.ActivityTags.onCreate(ActivityTags.java:75)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-26 12:03:04.740: E/AndroidRuntime(2800):     ... 11 more
11-26 12:03:04.740: E/AndroidRuntime(2800): Caused by: java.lang.reflect.InvocationTargetException
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.widget.Button.<init>(Button.java:65)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at java.lang.reflect.Constructor.constructNative(Native Method)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
11-26 12:03:04.740: E/AndroidRuntime(2800):     ... 26 more
11-26 12:03:04.740: E/AndroidRuntime(2800): Caused by: java.lang.StackOverflowError
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.StateListDrawable$StateListState.<init>(StateListDrawable.java:255)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.StateListDrawable.<init>(StateListDrawable.java:301)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.StateListDrawable.<init>(StateListDrawable.java:68)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:750)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.content.res.Resources.getDrawable(Resources.java:581)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:160)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.content.res.Resources.getDrawable(Resources.java:581)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:160)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.content.res.Resources.getDrawable(Resources.java:581)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:160)
11-26 12:03:04.740: E/AndroidRuntime(2800):     at android.graphics.drawable.Drawable.createF
4

1 回答 1

5

这个StackOverflowError例外让我认为你的header_button背景取决于它自己,所以它递归地加载同一个文件直到它死掉。

于 2012-11-26T20:02:59.913 回答