如果你不能不以不投票的方式投票..请给其他机会.....而且这个不重复我尝试了之前给出的所有解决方案
默认的activity_main.xml无效。所以我创建了另一个删除前一个。但是现在当我启动Avd时它(app)以msg关闭:“不幸的是app停止了工作”。
图形布局中的一切似乎都很好..它只是我认为的AVD
log Cat:
11-20 22:07:17.326 2381-2381/? I/art: Not late-enabling -Xcheck:jni (already on)
11-20 22:07:18.198 2381-2384/com.example.abhinav.vendue W/art: Suspending all threads took: 5.062ms
11-20 22:07:19.330 2381-2381/com.example.abhinav.vendue I/art: WaitForGcToComplete blocked for 9.928ms for cause Alloc
11-20 22:07:19.378 2381-2381/com.example.abhinav.vendue I/art: Alloc sticky concurrent mark sweep GC freed 2821(231KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 679KB/1117KB, paused 4.957ms total 39.087ms
11-20 22:07:19.418 2381-2381/com.example.abhinav.vendue I/art: Alloc partial concurrent mark sweep GC freed 163(19KB) AllocSpace objects, 0(0B) LOS objects, 60% free, 659KB/1683KB, paused 4.529ms total 35.334ms
11-20 22:07:19.425 2381-2381/com.example.abhinav.vendue W/art: Suspending all threads took: 6.134ms
11-20 22:07:19.486 2381-2381/com.example.abhinav.vendue I/art: Alloc concurrent mark sweep GC freed 15(12KB) AllocSpace objects, 0(0B) LOS objects, 61% free, 647KB/1671KB, paused 3.219ms total 51.322ms
11-20 22:07:19.488 2381-2381/com.example.abhinav.vendue I/art: Forcing collection of SoftReferences for 97MB allocation
11-20 22:07:19.637 2381-2381/com.example.abhinav.vendue I/art: Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 61% free, 647KB/1671KB, paused 36.059ms total 116.237ms
11-20 22:07:19.648 2381-2381/com.example.abhinav.vendue E/art: Throwing OutOfMemoryError "Failed to allocate a 102400012 byte allocation with 1048576 free bytes and 63MB until OOM"
11-20 22:07:19.667 2381-2381/com.example.abhinav.vendue I/art: WaitForGcToComplete blocked for 18.213ms for cause Alloc
11-20 22:07:19.686 2381-2384/com.example.abhinav.vendue W/art: Suspending all threads took: 11.017ms
11-20 22:07:19.728 2381-2381/com.example.abhinav.vendue I/art: Alloc sticky concurrent mark sweep GC freed 5(608B) AllocSpace objects, 0(0B) LOS objects, 61% free, 647KB/1671KB, paused 4.534ms total 59.137ms
11-20 22:07:19.772 2381-2381/com.example.abhinav.vendue I/art: Alloc partial concurrent mark sweep GC freed 10(320B) AllocSpace objects, 0(0B) LOS objects, 61% free, 647KB/1671KB, paused 6.520ms total 39.893ms
11-20 22:07:19.822 2381-2381/com.example.abhinav.vendue I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 61% free, 647KB/1671KB, paused 7.644ms total 39.046ms
11-20 22:07:19.832 2381-2381/com.example.abhinav.vendue I/art: Forcing collection of SoftReferences for 97MB allocation
11-20 22:07:19.870 2381-2381/com.example.abhinav.vendue I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 61% free, 647KB/1671KB, paused 3.137ms total 35.320ms
11-20 22:07:19.876 2381-2381/com.example.abhinav.vendue E/art: Throwing OutOfMemoryError "Failed to allocate a 102400012 byte allocation with 1048576 free bytes and 63MB until OOM"
11-20 22:07:19.876 2381-2381/com.example.abhinav.vendue D/skia: --- allocation failed for scaled bitmap
11-20 22:07:19.883 2381-2381/com.example.abhinav.vendue D/AndroidRuntime: Shutting down VM
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: FATAL EXCEPTION: main
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: Process: com.example.abhinav.vendue, PID: 2381
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 102400012 byte allocation with 1048576 free bytes and 63MB until OOM
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.content.res.Resources.loadDrawableForCookie(Resources.java:2474)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.content.res.Resources.loadDrawable(Resources.java:2381)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.view.View.<init>(View.java:3737)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.widget.TextView.<init>(TextView.java:637)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.widget.Button.<init>(Button.java:111)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.widget.Button.<init>(Button.java:107)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:63)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:59)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.support.v7.internal.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:101)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:806)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:836)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at com.example.abhinav.vendue.MainActivity.onCreate(MainActivity.java:21)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5990)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5257)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
11-20 22:07:19.885 2381-2381/com.example.abhinav.vendue E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
11-20 22:07:20.818 2381-2384/com.example.abhinav.vendue W/art: Suspending all threads took: 89.265ms
11-20 22:07:21.314 2381-2384/com.example.abhinav.vendue W/art: Suspending all threads took: 65.580ms
11-20 22:07:23.988 2381-2381/? I/Process: Sending signal. PID: 2381 SIG: 9
答案 0 :(得分:2)
OutOfMemoryError 是android中最常见的问题,尤其是在处理位图时。当由于内存空间不足而无法分配对象时,Java虚拟机(JVM)会抛出此错误,垃圾收集器也无法释放一些空间。
我认为你应该在Android的开发者页面上阅读一些内容,特别是在这里:Displaying Bitmaps Efficiently
阅读所有5节课,然后重新编写代码。如果它仍然无法正常工作,我们将很高兴看到您对教程材料的错误。
这里有一些SOF中这类错误的可能答案
Android: BitmapFactory.decodeStream() out of memory with a 400KB file with 2MB free heap
How to solve java.lang.OutOfMemoryError trouble in Android
Android : java.lang.OutOfMemoryError
Solution for OutOfMemoryError: bitmap size exceeds VM budget