我有一个带有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
答案 0 :(得分:5)
StackOverflowError
异常让我觉得你的header_button
背景依赖于它自己,所以它会递归加载同一个文件,直到它死掉。