OutOfMemory 异常 android
OutOfMemory exception android
我在 android playstore 上发布了一个应用程序,很多人都没有问题地尝试过,但是在 android 手机(Galaxy note III)上应用程序冻结了,我在我的开发者控制台上收到了这条消息在 android 个帐户中。
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.cade.codigos/org.cade.codigos.ui.activities.RequestDataForm}: android.view.InflateException: Binary XML file line #11: Error inflating class android.widget.RelativeLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2294)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2348)
at android.app.ActivityThread.access0(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5414)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.widget.RelativeLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)
at android.app.Activity.setContentView(Activity.java:1956)
at org.cade.codigos.ui.activities.RequestDataForm.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5369)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
... 25 more
Caused by: 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:832)
at android.content.res.Resources.loadDrawable(Resources.java:2988)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3563)
at android.view.View.<init>(View.java:3492)
at android.view.ViewGroup.<init>(ViewGroup.java:469)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:242)
... 28 more
这是我的布局
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="org.cade.codigos.ui.activities.RequestDataForm"
android:background="@drawable/background">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="NOMBRE*"
android:id="@+id/lblNombre"
android:layout_marginTop="80dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:textSize="15dp"
android:textColor="#e7f5fe"
android:layout_marginBottom="5dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtNombre"
android:hint="@string/hint_nombre"
android:layout_below="@+id/lblNombre"
android:layout_alignParentRight="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="APELLIDO*"
android:id="@+id/lblApellido"
android:layout_below="@+id/txtNombre"
android:layout_alignParentRight="true"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtApellido"
android:hint="@string/hint_apellido"
android:layout_below="@+id/lblApellido"
android:layout_alignParentRight="true" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ENVIAR"
android:textColor="#e7f5fe"
android:id="@+id/btnEnviar"
android:background="@drawable/button_form"
android:minHeight="41dp"
android:layout_below="@+id/txtCelularRecomendar2"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="MAIL*"
android:id="@+id/lblMail"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtEmpresa"
android:layout_alignRight="@+id/txtEmpresa"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/txtMail"
android:hint="@string/hint_mail"
android:layout_below="@+id/lblMail"
android:layout_alignRight="@+id/lblMensajeRecomendar" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="CELULAR*"
android:id="@+id/lblCelular"
android:layout_below="@+id/txtMail"
android:layout_alignParentLeft="true"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/txtCelular"
android:hint="@string/hint_celular_recomendar"
android:layout_below="@+id/lblCelular"
android:layout_alignParentLeft="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="PROFESIÓN*"
android:id="@+id/lblProfesion"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtApellido"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtProfesion"
android:hint="@string/hint_profesion"
android:layout_below="@+id/lblProfesion"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="EMPRESA"
android:id="@+id/lblEmpresa"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtProfesion"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtEmpresa"
android:hint="@string/hint_empresa"
android:layout_below="@+id/lblEmpresa"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="NÚMERO DE CLIENTE"
android:id="@+id/lblNumeroCliente"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtCelular"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/txtNumeroCliente"
android:hint="@string/hint_numero_cliente"
android:layout_below="@+id/lblNumeroCliente"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="RECOMIENDE AMIGOS PARA REGALARLE LA APLICACIÓN "CADE-CODIGOS" Y PARTICIPE DEL SORTEO DE UN "CURSO-CADE" A SU ELECCIÓN(TENDRÁ UNA CHANCE POR CADA AMIGO RECOMENDADO)"
android:id="@+id/lblMensajeRecomendar"
android:textSize="15dp"
android:textColor="#e7f5fe"
android:layout_below="@+id/txtNumeroCliente"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="3dp"
android:layout_marginLeft="1dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtMailRecomendar1"
android:hint="@string/hint_email_recomendar"
android:layout_below="@+id/lblMailRecomendar1"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="MAIL "
android:id="@+id/lblMailRecomendar1"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtApellidoRecomendar1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="CELULAR"
android:id="@+id/lblCelularRecomendar1"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtMailRecomendar1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtCelularRecomendar1"
android:hint="@string/hint_celular_recomendar"
android:layout_below="@+id/lblCelularRecomendar1"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="NOMBRE"
android:id="@+id/lblNombreRecomendar1"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/lblAmigo1"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtNombreRecomendar1"
android:hint="@string/hint_nombre"
android:layout_below="@+id/lblNombreRecomendar1"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="APELLIDO"
android:id="@+id/lblApellidoRecomendar1"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtNombreRecomendar1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtApellidoRecomendar1"
android:hint="@string/hint_apellido"
android:layout_below="@+id/lblApellidoRecomendar1"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="AMIGO 1"
android:id="@+id/lblAmigo1"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/lblMensajeRecomendar"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="AMIGO 2"
android:id="@+id/lblAmigo2"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtCelularRecomendar1"
android:layout_alignRight="@+id/lblMensajeRecomendar"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="NOMBRE"
android:id="@+id/lblNombreRecomendar2"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/lblAmigo2"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtNombreRecomendar2"
android:hint="@string/hint_nombre"
android:layout_below="@+id/lblNombreRecomendar2"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="APELLIDO"
android:id="@+id/lblApellidoRecomendar2"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtNombreRecomendar2"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtApellidoRecomendar2"
android:hint="@string/hint_apellido"
android:layout_below="@+id/lblApellidoRecomendar2"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="MAIL "
android:id="@+id/lblMailRecomendar2"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtApellidoRecomendar2"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtMailRecomendar2"
android:hint="@string/hint_email_recomendar"
android:layout_below="@+id/lblMailRecomendar2"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="CELULAR"
android:id="@+id/lblCelularRecomendar2"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtMailRecomendar2"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtCelularRecomendar2"
android:hint="@string/hint_celular_recomendar"
android:layout_below="@+id/lblCelularRecomendar2"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
正如@Cosmin 所说,您的问题似乎是 'out of memory' 由 Loading Bitmap without treatment(load large images) 引起的。
很多人都会遇到这个问题,我的建议是:
阅读 this
之后,您将了解如何在 android 中使用位图。
这是什么原因?
主要原因可能是您的应用程序中存在一处或多处内存泄漏,或者您只是试图在此布局中分配过多的内存。它可能与您尝试显示的 number/size 个图像位于此布局上,也可能位于先前的布局上,该布局仍保留对正在占用内存的位图的引用。这会在任何设备上发生,但三星 Galaxy III 的内存比更新的 phones 少,这可能是它在 phone.
上经常发生的原因
如何找到解决方案?
只有一种方法可以检测您的问题。
打开导致应用程序崩溃的activity,此时进行内存转储。
打开另一个 activity,并在此处创建内存转储。
分析内存转储并尝试查找内存泄漏。
只有你能理解内存泄漏在哪里(它可以是一个大图像,或者你使用了很多静态对象,可能还没有关闭流等),以及内存转储会在这次旅行中帮助你。
记住,这个问题只有你自己才能解决,解决了以后就不会再犯同样的错误了!!
祝你好运!
另见
P.S.
我刚刚分析了你的错误堆栈,发现OutOfMemory导致你的drawable,它已经从资源中加载,如果它是一个图像,你可以为它降低分辨率,也许问题就会消失。
Caused by: 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:832)
at android.content.res.Resources.loadDrawable(Resources.java:2988)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
希望this topic能帮到你!
P.S.S.
看起来你的 logo 图像占用大量内存(它太大 - 高分辨率),它可能会导致你的问题,进行内存转储并分析占用了多少字节
我可以看到,在您的 RelativeLayout 中,您使用的是自定义背景 @drawable/background
。如果此资源(PNG、JPG 或 9 Patch Drawable)未正确优化以支持多个屏幕和设备,那么这可能会导致您在 RAM 量较低的设备上出现 OutOfMemory 异常,其中 HEAP 太小而无法处理该数量的像素.请确保相应地优化了该资源:
http://developer.android.com/guide/practices/screens_support.html
我在 android playstore 上发布了一个应用程序,很多人都没有问题地尝试过,但是在 android 手机(Galaxy note III)上应用程序冻结了,我在我的开发者控制台上收到了这条消息在 android 个帐户中。
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.cade.codigos/org.cade.codigos.ui.activities.RequestDataForm}: android.view.InflateException: Binary XML file line #11: Error inflating class android.widget.RelativeLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2294)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2348)
at android.app.ActivityThread.access0(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5414)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.widget.RelativeLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)
at android.app.Activity.setContentView(Activity.java:1956)
at org.cade.codigos.ui.activities.RequestDataForm.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5369)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
... 25 more
Caused by: 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:832)
at android.content.res.Resources.loadDrawable(Resources.java:2988)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3563)
at android.view.View.<init>(View.java:3492)
at android.view.ViewGroup.<init>(ViewGroup.java:469)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:242)
... 28 more
这是我的布局
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="org.cade.codigos.ui.activities.RequestDataForm"
android:background="@drawable/background">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="NOMBRE*"
android:id="@+id/lblNombre"
android:layout_marginTop="80dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:textSize="15dp"
android:textColor="#e7f5fe"
android:layout_marginBottom="5dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtNombre"
android:hint="@string/hint_nombre"
android:layout_below="@+id/lblNombre"
android:layout_alignParentRight="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="APELLIDO*"
android:id="@+id/lblApellido"
android:layout_below="@+id/txtNombre"
android:layout_alignParentRight="true"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtApellido"
android:hint="@string/hint_apellido"
android:layout_below="@+id/lblApellido"
android:layout_alignParentRight="true" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ENVIAR"
android:textColor="#e7f5fe"
android:id="@+id/btnEnviar"
android:background="@drawable/button_form"
android:minHeight="41dp"
android:layout_below="@+id/txtCelularRecomendar2"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="MAIL*"
android:id="@+id/lblMail"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtEmpresa"
android:layout_alignRight="@+id/txtEmpresa"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/txtMail"
android:hint="@string/hint_mail"
android:layout_below="@+id/lblMail"
android:layout_alignRight="@+id/lblMensajeRecomendar" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="CELULAR*"
android:id="@+id/lblCelular"
android:layout_below="@+id/txtMail"
android:layout_alignParentLeft="true"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/txtCelular"
android:hint="@string/hint_celular_recomendar"
android:layout_below="@+id/lblCelular"
android:layout_alignParentLeft="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="PROFESIÓN*"
android:id="@+id/lblProfesion"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtApellido"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtProfesion"
android:hint="@string/hint_profesion"
android:layout_below="@+id/lblProfesion"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="EMPRESA"
android:id="@+id/lblEmpresa"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtProfesion"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtEmpresa"
android:hint="@string/hint_empresa"
android:layout_below="@+id/lblEmpresa"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="NÚMERO DE CLIENTE"
android:id="@+id/lblNumeroCliente"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtCelular"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/txtNumeroCliente"
android:hint="@string/hint_numero_cliente"
android:layout_below="@+id/lblNumeroCliente"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="RECOMIENDE AMIGOS PARA REGALARLE LA APLICACIÓN "CADE-CODIGOS" Y PARTICIPE DEL SORTEO DE UN "CURSO-CADE" A SU ELECCIÓN(TENDRÁ UNA CHANCE POR CADA AMIGO RECOMENDADO)"
android:id="@+id/lblMensajeRecomendar"
android:textSize="15dp"
android:textColor="#e7f5fe"
android:layout_below="@+id/txtNumeroCliente"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="3dp"
android:layout_marginLeft="1dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtMailRecomendar1"
android:hint="@string/hint_email_recomendar"
android:layout_below="@+id/lblMailRecomendar1"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="MAIL "
android:id="@+id/lblMailRecomendar1"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtApellidoRecomendar1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="CELULAR"
android:id="@+id/lblCelularRecomendar1"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtMailRecomendar1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtCelularRecomendar1"
android:hint="@string/hint_celular_recomendar"
android:layout_below="@+id/lblCelularRecomendar1"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="NOMBRE"
android:id="@+id/lblNombreRecomendar1"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/lblAmigo1"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtNombreRecomendar1"
android:hint="@string/hint_nombre"
android:layout_below="@+id/lblNombreRecomendar1"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="APELLIDO"
android:id="@+id/lblApellidoRecomendar1"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtNombreRecomendar1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtApellidoRecomendar1"
android:hint="@string/hint_apellido"
android:layout_below="@+id/lblApellidoRecomendar1"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="AMIGO 1"
android:id="@+id/lblAmigo1"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/lblMensajeRecomendar"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="AMIGO 2"
android:id="@+id/lblAmigo2"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtCelularRecomendar1"
android:layout_alignRight="@+id/lblMensajeRecomendar"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="NOMBRE"
android:id="@+id/lblNombreRecomendar2"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/lblAmigo2"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtNombreRecomendar2"
android:hint="@string/hint_nombre"
android:layout_below="@+id/lblNombreRecomendar2"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="APELLIDO"
android:id="@+id/lblApellidoRecomendar2"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtNombreRecomendar2"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtApellidoRecomendar2"
android:hint="@string/hint_apellido"
android:layout_below="@+id/lblApellidoRecomendar2"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="MAIL "
android:id="@+id/lblMailRecomendar2"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtApellidoRecomendar2"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtMailRecomendar2"
android:hint="@string/hint_email_recomendar"
android:layout_below="@+id/lblMailRecomendar2"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="CELULAR"
android:id="@+id/lblCelularRecomendar2"
android:textSize="15dp"
android:textColor="#E6E6E6"
android:layout_below="@+id/txtMailRecomendar2"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtCelularRecomendar2"
android:hint="@string/hint_celular_recomendar"
android:layout_below="@+id/lblCelularRecomendar2"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
正如@Cosmin 所说,您的问题似乎是 'out of memory' 由 Loading Bitmap without treatment(load large images) 引起的。
很多人都会遇到这个问题,我的建议是: 阅读 this
之后,您将了解如何在 android 中使用位图。
这是什么原因?
主要原因可能是您的应用程序中存在一处或多处内存泄漏,或者您只是试图在此布局中分配过多的内存。它可能与您尝试显示的 number/size 个图像位于此布局上,也可能位于先前的布局上,该布局仍保留对正在占用内存的位图的引用。这会在任何设备上发生,但三星 Galaxy III 的内存比更新的 phones 少,这可能是它在 phone.
上经常发生的原因如何找到解决方案?
只有一种方法可以检测您的问题。
打开导致应用程序崩溃的activity,此时进行内存转储。
打开另一个 activity,并在此处创建内存转储。
分析内存转储并尝试查找内存泄漏。
只有你能理解内存泄漏在哪里(它可以是一个大图像,或者你使用了很多静态对象,可能还没有关闭流等),以及内存转储会在这次旅行中帮助你。
记住,这个问题只有你自己才能解决,解决了以后就不会再犯同样的错误了!!
祝你好运!
另见
P.S.
我刚刚分析了你的错误堆栈,发现OutOfMemory导致你的drawable,它已经从资源中加载,如果它是一个图像,你可以为它降低分辨率,也许问题就会消失。
Caused by: 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:832)
at android.content.res.Resources.loadDrawable(Resources.java:2988)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
希望this topic能帮到你!
P.S.S.
看起来你的 logo 图像占用大量内存(它太大 - 高分辨率),它可能会导致你的问题,进行内存转储并分析占用了多少字节
我可以看到,在您的 RelativeLayout 中,您使用的是自定义背景 @drawable/background
。如果此资源(PNG、JPG 或 9 Patch Drawable)未正确优化以支持多个屏幕和设备,那么这可能会导致您在 RAM 量较低的设备上出现 OutOfMemory 异常,其中 HEAP 太小而无法处理该数量的像素.请确保相应地优化了该资源:
http://developer.android.com/guide/practices/screens_support.html