使用翻转按钮时应用程序崩溃

时间:2014-01-09 11:01:27

标签: android android-layout button

编辑:确定重复

当我尝试将setContentView()方法调用到布局时,我的应用程序崩溃了。

我尝试了一些解决方案,当我删除按钮的样式时,错误就消失了。

似乎我用于按钮的样式导致了这种情况。

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/lights_over" />
<item android:state_focused="true" android:drawable="@drawable/lights_over" />
<item android:state_selected = "true" android:drawable = "@drawable/lights_over" />
<item android:drawable = "@drawable/lights" android:id="@+id/button_L"/>
</selector>

我的LogCat

01-09 12:04:24.161: D/dalvikvm(20682): GC_BEFORE_OOM freed 9K, 5% free 122880K/129056K, paused 20ms, total 20ms
01-09 12:04:24.161: E/dalvikvm-heap(20682): Out of memory on a 9027940-byte allocation.
01-09 12:04:24.171: E/AndroidRuntime(20682): FATAL EXCEPTION: main
01-09 12:04:24.171: E/AndroidRuntime(20682): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidexample.broadcastreceiver/com.androidexample.broadcastreceiver.StartMenu}: android.view.InflateException: Binary XML file line #79: Error inflating class <unknown>
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.app.ActivityThread.access$700(ActivityThread.java:151)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.os.Looper.loop(Looper.java:137)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.app.ActivityThread.main(ActivityThread.java:5293)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at java.lang.reflect.Method.invokeNative(Native Method)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at java.lang.reflect.Method.invoke(Method.java:511)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at dalvik.system.NativeStart.main(Native Method)
01-09 12:04:24.171: E/AndroidRuntime(20682): Caused by: android.view.InflateException: Binary XML file line #79: Error inflating class <unknown>
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.view.LayoutInflater.createView(LayoutInflater.java:619)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:327)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.app.Activity.setContentView(Activity.java:1928)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at com.androidexample.broadcastreceiver.StartMenu.onCreate(StartMenu.java:20)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.app.Activity.performCreate(Activity.java:5250)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
01-09 12:04:24.171: E/AndroidRuntime(20682):    ... 11 more
01-09 12:04:24.171: E/AndroidRuntime(20682): Caused by: java.lang.reflect.InvocationTargetException
01-09 12:04:24.171: E/AndroidRuntime(20682):    at java.lang.reflect.Constructor.constructNative(Native Method)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.view.LayoutInflater.createView(LayoutInflater.java:593)
01-09 12:04:24.171: E/AndroidRuntime(20682):    ... 25 more
01-09 12:04:24.171: E/AndroidRuntime(20682): Caused by: java.lang.OutOfMemoryError
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.content.res.Resources.loadDrawable(Resources.java:2854)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.content.res.Resources.getDrawable(Resources.java:1521)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:921)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:858)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.content.res.Resources.loadDrawable(Resources.java:2839)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.view.View.<init>(View.java:3460)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.widget.TextView.<init>(TextView.java:791)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.widget.Button.<init>(Button.java:107)
01-09 12:04:24.171: E/AndroidRuntime(20682):    at android.widget.Button.<init>(Button.java:103)
01-09 12:04:24.171: E/AndroidRuntime(20682):    ... 28 more

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

这是一个OutOfMemoryError,因此您在选择器中使用的drawable似乎很重。