我有一个仪表板布局,有几个图像。当我运行应用程序时,我得到强制关闭错误,错误指向仪表板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
这是我的一个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>
答案 0 :(得分:2)
您有可绘制的圆形定义。一个(或多个)选择器引用再次引用选择器的内容。 (或者它可能引用自己。)
(在我看来,资源编译器应该抓住这个,但显然没有。)