我编辑了splash.xml文件,当我尝试运行该应用时,我收到了“遗憾的应用已停止”错误。
在我编辑它之前,这个splash.xml文件中有2个图像(当应用程序运行时)
我试图重新运行Eclipse和模拟器,但同样的问题
这是原始的splash.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/main_bg"
android:gravity="center" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="180.0dip"
android:layout_height="180.0dip"
android:layout_below="@+id/imageView2"
android:layout_centerHorizontal="true"
android:src="@drawable/iconmain"
android:contentDescription="@string/app_name"/>
<ImageView
android:id="@+id/imageView2"
android:layout_width="180.0dip"
android:layout_height="105.0dip"
android:layout_alignLeft="@+id/imageView1"
android:layout_alignParentTop="true"
android:layout_marginTop="14.0dip"
android:src="@drawable/title"
android:contentDescription="@string/app_name"/>
</RelativeLayout>
这是修改后的版本:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/main_bg"
android:gravity="center" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/applogofull"/>
</RelativeLayout>
这是LogCat:
10-30 06:11:11.840: I/art(1961): Debugger is active
10-30 06:11:11.999: I/System.out(1961): Debugger has connected
10-30 06:11:11.999: I/System.out(1961): waiting for debugger to settle...
10-30 06:11:12.203: I/System.out(1961): waiting for debugger to settle...
10-30 06:11:12.403: I/System.out(1961): waiting for debugger to settle...
10-30 06:11:12.603: I/System.out(1961): waiting for debugger to settle...
10-30 06:11:12.803: I/System.out(1961): waiting for debugger to settle...
10-30 06:11:13.004: I/System.out(1961): waiting for debugger to settle...
10-30 06:11:13.204: I/System.out(1961): waiting for debugger to settle...
10-30 06:11:13.404: I/System.out(1961): waiting for debugger to settle...
10-30 06:11:13.605: I/System.out(1961): waiting for debugger to settle...
10-30 06:11:13.805: I/System.out(1961): waiting for debugger to settle...
10-30 06:11:14.006: I/System.out(1961): debugger has settled (1485)
10-30 06:11:14.554: I/art(1961): Alloc sticky concurrent mark sweep GC freed 1724(90KB) AllocSpace objects, 0(0B) LOS objects, 26% free, 22MB/30MB, paused 289us total 37.744ms
10-30 06:11:14.560: I/art(1961): Alloc partial concurrent mark sweep GC freed 65(15KB) AllocSpace objects, 0(0B) LOS objects, 40% free, 22MB/36MB, paused 491us total 5.432ms
10-30 06:11:14.569: I/art(1961): Alloc concurrent mark sweep GC freed 17(12KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 22MB/36MB, paused 402us total 9.377ms
10-30 06:11:14.570: I/art(1961): Forcing collection of SoftReferences for 462MB allocation
10-30 06:11:14.582: I/art(1961): Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 39% free, 22MB/36MB, paused 2.325ms total 12.381ms
10-30 06:11:14.582: E/art(1961): Throwing OutOfMemoryError "Failed to allocate a 485258948 byte allocation with 15447336 free bytes and 73MB until OOM"
10-30 06:11:14.600: I/art(1961): Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 39% free, 22MB/36MB, paused 1.374ms total 10.202ms
10-30 06:11:14.600: I/art(1961): Forcing collection of SoftReferences for 462MB allocation
10-30 06:11:14.609: I/art(1961): Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 39% free, 22MB/36MB, paused 788us total 8.989ms
10-30 06:11:14.610: E/art(1961): Throwing OutOfMemoryError "Failed to allocate a 485258948 byte allocation with 15447336 free bytes and 73MB until OOM"
10-30 06:11:14.610: D/skia(1961): --- allocation failed for scaled bitmap
10-30 06:11:14.613: D/AndroidRuntime(1961): Shutting down VM
10-30 06:11:14.619: E/AndroidRuntime(1961): FATAL EXCEPTION: main
10-30 06:11:14.619: E/AndroidRuntime(1961): Process: com.AbdellahASKI.SoundQuiz, PID: 1961
10-30 06:11:14.619: E/AndroidRuntime(1961): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.AbdellahASKI.SoundQuiz/com.AbdellahASKI.SoundQuiz.SplashActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageView
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.app.ActivityThread.access$800(ActivityThread.java:151)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.os.Handler.dispatchMessage(Handler.java:102)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.os.Looper.loop(Looper.java:135)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.app.ActivityThread.main(ActivityThread.java:5254)
10-30 06:11:14.619: E/AndroidRuntime(1961): at java.lang.reflect.Method.invoke(Native Method)
10-30 06:11:14.619: E/AndroidRuntime(1961): at java.lang.reflect.Method.invoke(Method.java:372)
10-30 06:11:14.619: E/AndroidRuntime(1961): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
10-30 06:11:14.619: E/AndroidRuntime(1961): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
10-30 06:11:14.619: E/AndroidRuntime(1961): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageView
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.view.LayoutInflater.createView(LayoutInflater.java:633)
10-30 06:11:14.619: E/AndroidRuntime(1961): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
10-30 06:11:14.619: E/AndroidRuntime(1961): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.app.Activity.setContentView(Activity.java:2145)
10-30 06:11:14.619: E/AndroidRuntime(1961): at com.AbdellahASKI.SoundQuiz.SplashActivity.onCreate(SplashActivity.java:20)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.app.Activity.performCreate(Activity.java:5990)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
10-30 06:11:14.619: E/AndroidRuntime(1961): ... 10 more
10-30 06:11:14.619: E/AndroidRuntime(1961): Caused by: java.lang.reflect.InvocationTargetException
10-30 06:11:14.619: E/AndroidRuntime(1961): at java.lang.reflect.Constructor.newInstance(Native Method)
10-30 06:11:14.619: E/AndroidRuntime(1961): at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.view.LayoutInflater.createView(LayoutInflater.java:607)
10-30 06:11:14.619: E/AndroidRuntime(1961): ... 23 more
10-30 06:11:14.619: E/AndroidRuntime(1961): Caused by: java.lang.OutOfMemoryError: Failed to allocate a 485258948 byte allocation with 15447336 free bytes and 73MB until OOM
10-30 06:11:14.619: E/AndroidRuntime(1961): at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.content.res.Resources.loadDrawableForCookie(Resources.java:2474)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.content.res.Resources.loadDrawable(Resources.java:2381)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.widget.ImageView.<init>(ImageView.java:146)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.widget.ImageView.<init>(ImageView.java:135)
10-30 06:11:14.619: E/AndroidRuntime(1961): at android.widget.ImageView.<init>(ImageView.java:131)
10-30 06:11:14.619: E/AndroidRuntime(1961): ... 26 more
谢谢大家的帮助但是当我优化了Image并且我试图运行应用程序时,我在控制台上得到了另一个错误(最后一行是红色):
[2015-10-30 13:50:45 - SoundQuiz] Dx Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
[2015-10-30 13:50:45 - SoundQuiz] Dx 1 error; aborting
[2015-10-30 13:50:45 - SoundQuiz] Conversion to Dalvik format failed with error 1
答案 0 :(得分:1)
加载图像时超出内存限制。也许太大了。
可能有不同的方法:
告诉系统该应用需要更多内存,编辑清单以在android:largeHeap="true"
中添加application
<application
...
android:largeHeap="true" >
答案 1 :(得分:0)
你在drawable中添加的图像太大,无法在模拟器中分配内存,这就是为什么你得到OutOfmemory错误,因为RAM大小不足以处理图像,你可以通过减小它的大小来调整图像大小和决议。