Krishnaprasad K K Krishnaprasad K K - 4 months ago 30
Android Question

Android studio shows error when running my app with emulator redmi 2 prime kitkat

My android app does not run in my emulator.shows 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
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:621)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:670)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
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:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
at com.agte.agtevivo.Login.onCreate(Login.java:20)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5017) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:595)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:670) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
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:276) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136) 
at com.agte.agtevivo.Login.onCreate(Login.java:20) 
at android.app.Activity.performCreate(Activity.java:5231) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5017) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
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.(View.java:3554)
at android.view.View.(View.java:3484)
at android.view.ViewGroup.(ViewGroup.java:464)
at android.widget.RelativeLayout.(RelativeLayout.java:236)
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at android.view.LayoutInflater.createView(LayoutInflater.java:595) 
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:670) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
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:276) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136) 
at com.agte.agtevivo.Login.onCreate(Login.java:20) 
at android.app.Activity.performCreate(Activity.java:5231) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5017) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
at dalvik.system.NativeStart.main(Native Method) 

Added layout of login page

<?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>


and next am added layout of 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>


Next its my main activity



<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>

Answer

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
}

and also add

compile 'com.android.support:support-v4:23.4.0'

Then rebuild and run the project.. This will fix the error..

Comments