Android崩溃与OutOfMemoryError

时间:2015-06-08 16:38:58

标签: android

我有一些活动,里面有一些照片。当我停止工作时,我试图在手机中启动该活动。我所有的照片都是634x561尺寸。我发现在没有手机崩溃的情况下我最多可以拍摄6张照片。当我将图像缩小到100x88时,即使有12张图像,该应用也能正常工作,但我的质量会下降。我必须制作10个活动,其中共有306张图片。有可能吗?

我测试了各种尺寸的图像,并确定尺寸200x177对我来说是最好的。我的手机可以承受吗? (我正在使用三星Galaxy S4)

请注意,我不想使用android:largeHeap="true",因为Android开发者网站上说它不适合使用它。

logcat的:

06-08 19:31:25.894    7226-7226/com.ket_taisykles.kasparas.KET_taisykles E/SELinux﹕ [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
06-08 19:31:26.095    7226-7226/com.ket_taisykles.kasparas.KET_taisykles E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.ket_taisykles.kasparas.KET_taisykles, PID: 7226
    java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.IllegalStateException: Unable to get package info for com.ket_taisykles.kasparas.KET_taisykles; is package not installed?
            at android.app.LoadedApk.makeApplication(LoadedApk.java:625)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5088)
            at android.app.ActivityThread.access$1600(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5944)
            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:1389)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
     Caused by: java.lang.IllegalStateException: Unable to get package info for com.ket_taisykles.kasparas.KET_taisykles; is package not installed?
            at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:471)
            at android.app.LoadedApk.getClassLoader(LoadedApk.java:420)
            at android.app.LoadedApk.makeApplication(LoadedApk.java:615)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5088)
            at android.app.ActivityThread.access$1600(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5944)
            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:1389)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
06-08 19:31:36.315    7456-7456/com.ket_taisykles.kasparas.KET_taisykles E/libEGL﹕ call to OpenGL ES API with no current context (logged once per thread)
06-08 19:32:37.334    8482-8482/com.ket_taisykles.kasparas.KET_taisykles E/Zygote﹕ MountEmulatedStorage()
06-08 19:32:37.334    8482-8482/com.ket_taisykles.kasparas.KET_taisykles E/Zygote﹕ v2
06-08 19:32:37.404    8482-8482/com.ket_taisykles.kasparas.KET_taisykles E/SELinux﹕ [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
06-08 19:32:42.940    8482-8498/com.ket_taisykles.kasparas.KET_taisykles W/art﹕ Suspending all threads took: 41.717ms
06-08 19:32:43.790    8482-8482/com.ket_taisykles.kasparas.KET_taisykles E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 316812 byte allocation with 120176 free bytes and 117KB until OOM"
06-08 19:32:43.800    8482-8482/com.ket_taisykles.kasparas.KET_taisykles E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.ket_taisykles.kasparas.KET_taisykles, PID: 8482
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ket_taisykles.kasparas.KET_taisykles/com.ket_taisykles.kasparas.KET_taisykles.ispejamiejiZenklai1}: android.view.InflateException: Binary XML file line #624: Error inflating class <unknown>
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
            at android.app.ActivityThread.access$900(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5944)
            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:1389)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
     Caused by: android.view.InflateException: Binary XML file line #624: 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.rInflate(LayoutInflater.java:813)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.ket_taisykles.kasparas.KET_taisykles.ispejamiejiZenklai1.onCreate(ispejamiejiZenklai1.java:15)
            at android.app.Activity.performCreate(Activity.java:6289)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
            at android.app.ActivityThread.access$900(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5944)
            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:1389)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
     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.rInflate(LayoutInflater.java:813)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.ket_taisykles.kasparas.KET_taisykles.ispejamiejiZenklai1.onCreate(ispejamiejiZenklai1.java:15)
            at android.app.Activity.performCreate(Activity.java:6289)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
            at android.app.ActivityThread.access$900(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5944)
            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:1389)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
     Caused by: java.lang.OutOfMemoryError: Failed to allocate a 316812 byte allocation with 120176 free bytes and 117KB 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.widget.ImageView.<init>(ImageView.java:151)
            at android.widget.ImageView.<init>(ImageView.java:140)
            at android.widget.ImageView.<init>(ImageView.java:136)
            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.rInflate(LayoutInflater.java:813)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.ket_taisykles.kasparas.KET_taisykles.ispejamiejiZenklai1.onCreate(ispejamiejiZenklai1.java:15)
            at android.app.Activity.performCreate(Activity.java:6289)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
            at android.app.ActivityThread.access$900(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5944)
            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:1389)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)

我的一张XML图片:

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView4"
        android:src="@drawable/z_101"
        android:background="#00000000"
        android:scaleType="fitCenter"
        android:maxWidth="100dp"
        android:maxHeight="100dp"
        android:adjustViewBounds="true"
        android:layout_marginTop="30dp"
        android:layout_below="@+id/imageView103"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

0 个答案:

没有答案