Android工作室“java.lang.OutOfMemoryError”模拟器redmi 2 prime kitkat

时间:2016-07-20 04:48:02

标签: java android xml

当我的Android应用程序在我的模拟器中运行时,我看到以下错误:

     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>

1 个答案:

答案 0 :(得分:1)

您应该将build.gradle文件更新为

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'

然后rebuild and run the project ..这将解决错误..