本文介绍了Android工作室“java.lang.OutOfMemoryError"模拟器 redmi 2 prime kitkat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我的 android 应用程序在我的模拟器中运行时,我看到以下错误:
When my android app runs in my emulator I see the following error:
07-20 00:42:21.128 2492-2492/com.agte.agtevivo E/dalvikvm-heap: Out of memory on a 436615212-byte allocation.
07-20 00:42:21.148 2492-2492/com.agte.agtevivo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.agte.agtevivo, PID: 2492
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.agte.agtevivo/com.agte.agtevivo.Login}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2115)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3554)
at android.view.View.<init>(View.java:3484)
at android.view.ViewGroup.<init>(ViewGroup.java:464)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:236)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
新增登录页面布局
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/home"
tools:context="com.agte.agtevivo.Login">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="VIVO"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_alignParentEnd="false"
android:textSize="40dp"
android:textIsSelectable="false"
android:textColor="#6de6ec" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="User ID"
android:id="@+id/textView2"
android:layout_marginTop="48dp"
android:textSize="20dp"
android:textIsSelectable="false"
android:layout_marginEnd="30dp"
android:layout_below="@+id/textView"
android:layout_toStartOf="@+id/editText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Password"
android:id="@+id/textView3"
android:layout_below="@+id/textView2"
android:layout_alignStart="@+id/textView2"
android:layout_marginTop="52dp"
android:textSize="20dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_marginStart="49dp"
android:text="Enter Your ID"
android:layout_alignTop="@+id/textView2"
android:layout_alignStart="@+id/textView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText2"
android:text="Password"
android:layout_alignBottom="@+id/textView3"
android:layout_alignStart="@+id/editText"
android:layout_alignEnd="@+id/editText" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN"
android:id="@+id/login"
android:background="#56a5cf"
android:layout_below="@+id/editText2"
android:layout_marginTop="@dimen/abc_action_bar_progress_bar_size"
android:layout_alignEnd="@+id/editText2"
android:layout_marginLeft="@dimen/abc_action_bar_progress_bar_size"
android:layout_marginRight="@dimen/abc_action_bar_progress_bar_size"
android:layout_marginBottom="@dimen/abc_action_bar_progress_bar_size"
android:layout_alignStart="@+id/ratingBar" />
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:layout_marginBottom="37dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register Here"
android:id="@+id/textView8"
android:layout_below="@+id/login"
android:layout_centerHorizontal="true"
android:textSize="20dp"
android:textColor="#ee4646" />
</RelativeLayout>
然后添加寄存器布局
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/home"
tools:context="com.agte.agtevivo.Register">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Name"
android:id="@+id/textView4"
android:textSize="25dp"
android:layout_alignBottom="@+id/editText3"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="UserID"
android:id="@+id/textView5"
android:textSize="25dp"
android:layout_above="@+id/textView6"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Shop"
android:id="@+id/textView6"
android:layout_marginTop="47dp"
android:textSize="25dp"
android:layout_centerVertical="true"
android:layout_alignEnd="@+id/textView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Password"
android:id="@+id/textView7"
android:layout_marginTop="45dp"
android:textSize="25dp"
android:layout_below="@+id/editText5"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
android:id="@+id/editText3"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText4"
android:text="Enter your ID"
android:layout_alignTop="@+id/textView5"
android:layout_alignParentEnd="true"
android:layout_alignStart="@+id/editText5" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText5"
android:text="Shop Name"
android:layout_alignTop="@+id/textView6"
android:layout_alignParentEnd="true"
android:layout_alignStart="@+id/editText6" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText6"
android:text="Password"
android:layout_alignTop="@+id/textView7"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/button"
android:layout_below="@+id/editText6"
android:layout_centerHorizontal="true"
android:background="#6a9dcd" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:layout_marginTop="45dp"
android:ems="10"
android:id="@+id/editText7"
android:text="mobile no"
android:layout_below="@+id/editText3"
android:layout_alignStart="@+id/editText3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Number"
android:textSize="25dp"
android:id="@+id/textView9"
android:layout_alignBottom="@+id/editText7"
android:layout_alignParentStart="true" />
</RelativeLayout>
接下来是我的主要活动
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/other"
tools:context="com.agte.agtevivo.MainActivity">
<ImageButton
android:layout_width="160dp"
android:layout_height="160dp"
android:id="@+id/imageButton"
android:layout_alignParentStart="true"
android:background="@drawable/scheme"
android:layout_alignParentEnd="true" />
</RelativeLayout>
推荐答案
当你应该更新你的 build.gradle
文件到
As you should update you build.gradle
file to
apply plugin: 'com.android.application'
android {
dexOptions {
//incremental true
javaMaxHeapSize "2048M"
}
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.agte.agtevivo"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
并添加
compile 'com.android.support:support-v4:23.4.0'
然后重新构建并运行项目
..这将修复错误..
Then rebuild and run the project
.. This will fix the error..
这篇关于Android工作室“java.lang.OutOfMemoryError"模拟器 redmi 2 prime kitkat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!