StackOverflow错误,View.inflate异常

发布于 2024-12-25 15:25:02 字数 9273 浏览 0 评论 0原文

我有一个包含多个图像的仪表板布局。当我运行应用程序时,我收到强制关闭错误,并且错误指向仪表板 avtivty 中的这一行,其中膨胀了布局(即 setContentView(R.layout.dashboard)。我不明白为什么。我对其他图像使用了相同的仪表板布局,并且一切都很好。现在有六个图像,但尺寸更大,我不知道这是否是问题以及如何解决这个问题? 这是我的仪表板布局。

<com.utils.DashboardLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background" >

<Button
    android:id="@+id/home_btn_general_knowledge"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/general_knowledge_icon_bg_selector"
    android:onClick="onGeneralKnowledgeClick"
    android:text="General Knowledge" />

<Button
    android:id="@+id/home_btn_brainteasers"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/brain_teasers_icon_bg_selector"
    android:onClick="onBrainTeasersClick"
    android:text="Brain Teasers" />

<Button
    android:id="@+id/home_btn_movies"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/movies_icon_bg_selector"
    android:onClick="onMoviesClick"
    android:text="Movies" />

<Button
    android:id="@+id/home_btn_sports"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/sports_icon_bg_selector"
    android:onClick="onSportsClick"
    android:text="Sports" />

<Button
    android:id="@+id/home_btn_music"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/music_icon_bg_selector"
    android:onClick="onMusicClick"
    android:text="Music" />

<Button
    android:id="@+id/home_btn_celebrities"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/celebrity_icon_bg_selector"
    android:onClick="onCelebritiesClick"
    android:text="Celebrities" />

这是错误 logcat:

01-08 02:29:29.216: E/AndroidRuntime(4221): FATAL EXCEPTION: main
01-08 02:29:29.216: E/AndroidRuntime(4221): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hussein.android./com.hussein.android.DashBoardActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.Button
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.os.Looper.loop(Looper.java:123)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread.main(ActivityThread.java:3683)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at java.lang.reflect.Method.invokeNative(Native Method)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at java.lang.reflect.Method.invoke(Method.java:507)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at dalvik.system.NativeStart.main(Native Method)
01-08 02:29:29.216: E/AndroidRuntime(4221): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.Button
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.Activity.setContentView(Activity.java:1657)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at com.hussein.android.quizgame.DashBoardActivity.onCreate(DashBoardActivity.java:18)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-08 02:29:29.216: E/AndroidRuntime(4221):     ... 11 more
01-08 02:29:29.216: E/AndroidRuntime(4221): Caused by: java.lang.reflect.InvocationTargetException
01-08 02:29:29.216: E/AndroidRuntime(4221):     at java.lang.reflect.Constructor.constructNative(Native Method)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
01-08 02:29:29.216: E/AndroidRuntime(4221):     ... 22 more
01-08 02:29:29.216: E/AndroidRuntime(4221): Caused by: java.lang.StackOverflowError
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable$StateListState.indexOfStateSet(StateListDrawable.java:274)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable$StateListState.access$000(StateListDrawable.java:253)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.onStateChange(StateListDrawable.java:95)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.<init>(StateListDrawable.java:306)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.<init>(StateListDrawable.java:70)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:749)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.getDrawable(Resources.java:581)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.getDrawable(Resources.java:581)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.getDrawable(Resources.java:581)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXml(Dr
01-08 02:29:29.327: D/dalvikvm(4221): GC_CONCURRENT freed 284K, 52% free 2749K/5639K, external 6582K/8020K, paused 7ms+7ms

这是我的可绘制的 sports_icon_bg_selector.xml 之一

 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/sports" android:state_focused="true" android:state_pressed="false"/>
    <item android:drawable="@drawable/sports" android:state_focused="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/sports_blue" android:state_focused="false" android:state_pressed="true"/>
    <item android:drawable="@drawable/sports"/>
</selector>

i have a dashboard layout that has several images. When i run the app i get force close error and the error point to this line in dashboard avtivty where inflate the layout(i.e setContentView(R.layout.dashboard). I dont understand why. I used the same Dashboard layout with other images and all was fine. Now it has six images but much bigger in size. I don't know if this is the problem and how to solve this? thanks.
Here is my dashboardlayout.

<com.utils.DashboardLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background" >

<Button
    android:id="@+id/home_btn_general_knowledge"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/general_knowledge_icon_bg_selector"
    android:onClick="onGeneralKnowledgeClick"
    android:text="General Knowledge" />

<Button
    android:id="@+id/home_btn_brainteasers"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/brain_teasers_icon_bg_selector"
    android:onClick="onBrainTeasersClick"
    android:text="Brain Teasers" />

<Button
    android:id="@+id/home_btn_movies"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/movies_icon_bg_selector"
    android:onClick="onMoviesClick"
    android:text="Movies" />

<Button
    android:id="@+id/home_btn_sports"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/sports_icon_bg_selector"
    android:onClick="onSportsClick"
    android:text="Sports" />

<Button
    android:id="@+id/home_btn_music"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/music_icon_bg_selector"
    android:onClick="onMusicClick"
    android:text="Music" />

<Button
    android:id="@+id/home_btn_celebrities"
    style="@style/DPDashBoardButton"
    android:drawableTop="@drawable/celebrity_icon_bg_selector"
    android:onClick="onCelebritiesClick"
    android:text="Celebrities" />

Here is the error logcat:

01-08 02:29:29.216: E/AndroidRuntime(4221): FATAL EXCEPTION: main
01-08 02:29:29.216: E/AndroidRuntime(4221): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hussein.android./com.hussein.android.DashBoardActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.Button
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.os.Looper.loop(Looper.java:123)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread.main(ActivityThread.java:3683)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at java.lang.reflect.Method.invokeNative(Native Method)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at java.lang.reflect.Method.invoke(Method.java:507)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at dalvik.system.NativeStart.main(Native Method)
01-08 02:29:29.216: E/AndroidRuntime(4221): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.Button
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.Activity.setContentView(Activity.java:1657)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at com.hussein.android.quizgame.DashBoardActivity.onCreate(DashBoardActivity.java:18)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-08 02:29:29.216: E/AndroidRuntime(4221):     ... 11 more
01-08 02:29:29.216: E/AndroidRuntime(4221): Caused by: java.lang.reflect.InvocationTargetException
01-08 02:29:29.216: E/AndroidRuntime(4221):     at java.lang.reflect.Constructor.constructNative(Native Method)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
01-08 02:29:29.216: E/AndroidRuntime(4221):     ... 22 more
01-08 02:29:29.216: E/AndroidRuntime(4221): Caused by: java.lang.StackOverflowError
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable$StateListState.indexOfStateSet(StateListDrawable.java:274)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable$StateListState.access$000(StateListDrawable.java:253)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.onStateChange(StateListDrawable.java:95)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.<init>(StateListDrawable.java:306)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.<init>(StateListDrawable.java:70)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:749)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.getDrawable(Resources.java:581)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.getDrawable(Resources.java:581)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.content.res.Resources.getDrawable(Resources.java:581)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
01-08 02:29:29.216: E/AndroidRuntime(4221):     at android.graphics.drawable.Drawable.createFromXml(Dr
01-08 02:29:29.327: D/dalvikvm(4221): GC_CONCURRENT freed 284K, 52% free 2749K/5639K, external 6582K/8020K, paused 7ms+7ms

Here is a one of my the drawables sports_icon_bg_selector.xml

 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/sports" android:state_focused="true" android:state_pressed="false"/>
    <item android:drawable="@drawable/sports" android:state_focused="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/sports_blue" android:state_focused="false" android:state_pressed="true"/>
    <item android:drawable="@drawable/sports"/>
</selector>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光飞翔i 2025-01-01 15:25:02

您的绘图有一个循环定义。您的一个(或多个)选择器引用了再次引用该选择器的内容。 (或者它可能引用自身。)

(在我看来,资源编译器应该捕获这一点,但显然没有。)

You have a circular definition of your drawables. One (or more) of your selectors references something that references the selector again. (Or perhaps it references itself.)

(In my opinion, the resource compiler should catch this, but it apparently doesn't.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文