Studio ImageView错误强制关闭

时间:2016-03-04 23:02:08

标签: android performance android-layout android-fragments android-intent

任何人都知道如何修复此错误?一旦我打开具有代码的项目,活动将无法打开并且应用程序强制关闭我的XML具有大量照片的viewflipper,所以我认为应用程序处理太多了吗?

 03-05 03:34:03.409 6563-6563/org.intercode.lifeatceu E/AndroidRuntime: FATAL EXCEPTION: main
     java.lang.OutOfMemoryError
         at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
         at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
         at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
         at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
         at android.content.res.Resources.loadDrawable(Resources.java:2854)
         at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
         at android.widget.ImageView.<init>(ImageView.java:126)
         at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:58)
         at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:54)
         at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:95)
         at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938)
         at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992)
         at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:681)
         at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
         at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
         at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
         at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:846)
         at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
         at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
         at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
         at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
         at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
         at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
         at org.intercode.lifeatceu.PFOT.onCreate(PFOT.java:28)
         at android.app.Activity.performCreate(Activity.java:5255)
         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213)
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
         at android.app.ActivityThread.access$700(ActivityThread.java:154)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
         at android.os.Handler.dispatchMessage(Handler.java:99)
         at android.os.Looper.loop(Looper.java:137)
         at android.app.ActivityThread.main(ActivityThread.java:5306)
         at java.lang.reflect.Method.invokeNative(Native Method)
         at java.lang.reflect.Method.invoke(Method.java:511)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
         at dalvik.system.NativeStart.main(Native Method)

PFOT.java第28行是

setContentView(R.layout.pfot);

3 个答案:

答案 0 :(得分:0)

这是内存不足错误,您尝试显示的资源中有一个非常大的图像,并且超出了最大大小。检查XML布局是否适合绘制并缩小任何大型布局。

答案 1 :(得分:0)

这是因为你为你的进程消耗了太多的内存,这导致分配失败,在它接近填充之后。您应该考虑查看图像以及如何加载以及如何影响记忆。

答案 2 :(得分:0)

(1)使用Vectore Drawable代替png ans jpj文件

https://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html

(2)将此行添加到build.gradal文件

defaultConfig {

    vectorDrawables.useSupportLibrary = true
}

(3)在您的xml文件中,在父布局中添加此行

的xmlns:应用=&#34; HTTP://schemas.android.com/apk/res-auto"     的xmlns:工具=&#34; HTTP://schemas.android.com/tools"

(4)在ImageView中使用srcCompat属性,如下所示

<android.support.v7.widget.AppCompatImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/sf_tick"
                tools:ignore="MissingPrefix" />