单击按钮后,我的应用程序已停止

时间:2017-02-20 14:03:44

标签: android

02-20 13:57:58.601 5952-5952/com.counter.milion.milioncounter E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                Process: com.counter.milion.milioncounter, PID: 5952
                                                                                java.lang.RuntimeException: Unable to start activity ComponentInfo{com.counter.milion.milioncounter/com.counter.milion.milioncounter.Menu}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
                                                                                    at android.app.ActivityThread.access$900(ActivityThread.java:177)
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                    at android.os.Looper.loop(Looper.java:145)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5951)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
                                                                                 Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
                                                                                    at android.view.LayoutInflater.createView(LayoutInflater.java:640)
                                                                                    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
                                                                                    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
                                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
                                                                                    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:435)
                                                                                    at android.app.Activity.setContentView(Activity.java:2267)
                                                                                    at com.counter.milion.milioncounter.Menu.onCreate(Menu.java:35)
                                                                                    at android.app.Activity.performCreate(Activity.java:6289)
                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767) 
                                                                                    at android.app.ActivityThread.access$900(ActivityThread.java:177) 
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449) 
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                    at android.os.Looper.loop(Looper.java:145) 
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5951) 
                                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                                    at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) 
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 
                                                                                 Caused by: java.lang.reflect.InvocationTargetException
                                                                                    at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                                    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
                                                                                    at android.view.LayoutInflater.createView(LayoutInflater.java:614)
                                                                                    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
                                                                                    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689) 
                                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:483) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:366) 
                                                                                    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:435) 
                                                                                    at android.app.Activity.setContentView(Activity.java:2267) 
                                                                                    at com.counter.milion.milioncounter.Menu.onCreate(Menu.java:35) 
                                                                                    at android.app.Activity.performCreate(Activity.java:6289) 
                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655) 
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767) 
                                                                                    at android.app.ActivityThread.access$900(ActivityThread.java:177) 
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449) 
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                    at android.os.Looper.loop(Looper.java:145) 
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5951) 
                                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                                    at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) 
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 
                                                                                 Caused by: java.lang.OutOfMemoryError: Failed to allocate a 35389452 byte allocation with 16777216 free bytes and 32MB until OOM
                                                                                    at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                                    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                                                    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:726)
                                                                                    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:547)
                                                                                    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014)
                                                                                    at android.content.res.Resources.loadDrawableForCookie(Resources.java:3730)
                                                                                    at android.content.res.Resources.loadDrawable(Resources.java:3603)
                                                                                    at android.content.res.TypedArray.getDrawable(TypedArray.java:762)
                                                                                    at android.view.View.<init>(View.java:3970)
                                                                                    at android.view.ViewGroup.<init>(ViewGroup.java:507)
                                                                                    at android.widget.LinearLayout.<init>(LinearLayout.java:199)
                                                                                    at android.widget.LinearLayout.<init>(LinearLayout.java:195)
                                                                                    at android.widget.LinearLayout.<init>(LinearLayout.java:191)
                                                                                    at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                                                    at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
                                                                                    at android.view.LayoutInflater.createView(LayoutInflater.java:614) 
                                                                                    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
                                                                                    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689) 
                                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:483) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:366) 
                                                                                    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:435) 
                                                                                    at android.app.Activity.setContentView(Activity.java:2267) 
                                                                                    at com.counter.milion.milioncounter.Menu.onCreate(Menu.java:35) 
                                                                                    at android.app.Activity.performCreate(Activity.java:6289) 
                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655) 
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767) 
                                                                                    at android.app.ActivityThread.access$900(ActivityThread.java:177) 
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449) 
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                    at android.os.Looper.loop(Looper.java:145) 
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5951) 
                                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                                    at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) 
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 

2 个答案:

答案 0 :(得分:1)

你使用 android:onClick =“yourfunction”功能吗? 如果是,请检查您是否在xml顶部声明了正确的活动

 tools:context="youractivity"

然后一定要在你的班级实现这个功能:

public void yourclick(View v){...}

答案 1 :(得分:1)

阅读堆栈跟踪告诉我三件事:

  1. 您的活动无法加载,因为无法完成对XML布局的膨胀
  2. 您的XML布局无法完成​​膨胀,因为尝试创建位图时内存不足
  3. 最后,你的答案是:

    1. 您的XML布局正在尝试加载太多图片或图片,这些图片或图片对于分配给您的应用程序的内存来说太大了。
    2. 您可以通过多种方式解决这个问题,但最简单的方法是:

      • 缩小图像尺寸。 (通常这意味着解决。)
      • 确保您只保留内存中所需的图像。 (您可能正在加载屏幕外的图像。)

      希望这有帮助。