title: Android Studio: java.lang.OutOfMemoryError
body: <p>I am trying to get my application to display different views when Image buttons are clicked. Its a fairly simple application, but I cant test to see if it works because I keep getting an Out of Memory Error. Here is the java class</p>
  
  <p>Edit:</p>
  
  <p>I decreased the size of the button images by 50% and I still get an out of memory error. Additionally I added android:largeHeap="true" to the android manifest. Below are the original files but with updates</p>
  
  <p><strong>Dashboard.java</strong></p>
  
  <pre><code>    package com.pixel.deloitte.xprizeapplication;
  
  import android.graphics.Color;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.view.Window;
  import android.widget.TabHost;
  import android.widget.TextView;
  
  import java.io.IOException;
  
  public class Dashboard extends AppCompatActivity {
      //private TabHost tabHost;
      //private int[] tabs = {R.drawable.dashboardnotclicked,R.drawable.teamreviewnotclicked,R.drawable.teambiosnotclicked,R.drawable.mentornotclicked,R.drawable.schedulenotclicked};
      public static class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
          @Override
          public void uncaughtException(Thread thread, Throwable ex) {
              if (ex.getClass().equals(OutOfMemoryError.class)) {
                  try {
                      android.os.Debug.dumpHprofData("/sdcard/dump.hprof");
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
                  ex.printStackTrace();
              }
  
          }
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          //Thread.currentThread().setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.activity_dashboard);
          findViewById(R.id.login).setVisibility(View.VISIBLE);
      }
  
      public void buttonClick(View v){
          switch(v.getId()){
              case R.id.loginButton:
                  break;
              case R.id.dashboardbtn:
                  break;
              case R.id.teamreviewbtn:
                  break;
              case R.id.teambios:
                  break;
              case R.id.mentorsbtn:
                  break;
              case R.id.schedulebtn:
                  break;
          }
      }
  
  }
  </code></pre>
  
  <p>Here is the error I get, the error is thrown at setContentView(R.layout.activity_dashboard)</p>
  
  <p><strong>java.lang.OutOfMemoryError</strong></p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.pixel.deloitte.xprizeapplication, PID: 2573
                                                   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.widget.ImageView.&lt;init&gt;(ImageView.java:129)
                                                       at android.support.v7.widget.AppCompatImageView.&lt;init&gt;(AppCompatImageView.java:57)
                                                       at android.support.v7.widget.AppCompatImageView.&lt;init&gt;(AppCompatImageView.java:53)
                                                       at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
                                                       at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:1008)
                                                       at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1067)
                                                       at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                       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:280)
                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                       at com.pixel.deloitte.xprizeapplication.Dashboard.onCreate(Dashboard.java:36)
                                                       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)
  </code></pre>
  
  <p>Here is
  <strong>activity_dashboard.xml</strong></p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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="900dp"
      tools:context=".Dashboard"
      android:background="@color/AppBackground"&gt;
  
      &lt;ScrollView
          android:layout_width="match_parent"
          android:layout_height="850dp"
          android:id="@+id/scrollView" &gt;
  
          &lt;LinearLayout
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/login"&gt;
  
              &lt;ImageView
                  android:layout_width="761dp"
                  android:layout_height="876dp"
                  android:id="@+id/visioneervideo"
                  android:src="@drawable/video" /&gt;
  
              &lt;RelativeLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:background="@drawable/signin"&gt;
  
                  &lt;LinearLayout
                      android:orientation="vertical"
                      android:layout_width="295dp"
                      android:layout_height="200dp"
                      android:layout_marginBottom="203dp"
                      android:layout_alignParentBottom="true"
                      android:layout_centerHorizontal="true"&gt;
  
                      &lt;EditText
                          android:layout_width="295dp"
                          android:layout_height="49dp"
                          android:ems="10"
                          android:id="@+id/editText"
                          android:background="@drawable/username"
                          android:editable="true"
                          android:textColor="#FFFFFFFF"
                          android:textAlignment="center"
                          android:text="Username"
                          android:layout_alignParentTop="true"
                          android:layout_centerHorizontal="true" /&gt;
  
                      &lt;EditText
                          android:layout_width="295dp"
                          android:layout_height="49dp"
                          android:ems="10"
                          android:id="@+id/editText2"
                          android:background="@drawable/username"
                          android:editable="true"
                          android:textColor="#FFFFFFFF"
                          android:textAlignment="center"
                          android:text="Password"
                          android:layout_below="@+id/editText"
                          android:layout_alignLeft="@+id/editText"
                          android:layout_alignStart="@+id/editText" /&gt;
  
                      &lt;ImageView
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:id="@+id/loginButton"
                          android:src="@drawable/login"
                          android:onClick="buttonClick" /&gt;
                  &lt;/LinearLayout&gt;
              &lt;/RelativeLayout&gt;
  
          &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  
      &lt;ScrollView
          android:layout_width="match_parent"
          android:layout_height="850dp"
          android:id="@+id/scrollView2"
          android:background="@color/AppBackground"&gt;
  
          &lt;LinearLayout
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/appactivities"&gt;
  
              &lt;LinearLayout
                  android:orientation="horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="64dp"
                  android:id="@+id/optionsmenu"
                  android:background="@color/DashboardBackgroundnew"&gt;
  
                  &lt;ImageView
                      android:layout_width="241dp"
                      android:layout_height="wrap_content"
                      android:id="@+id/xprizelogo"
                      android:background="@drawable/xprizelogo" /&gt;
  
                  &lt;ImageView
                      android:layout_width="141dp"
                      android:layout_height="wrap_content"
                      android:id="@+id/dashboardbtn"
                      android:background="@drawable/ic_dashboard" /&gt;
  
                  &lt;ImageView
                      android:layout_width="148dp"
                      android:layout_height="wrap_content"
                      android:id="@+id/teamreviewbtn"
                      android:background="@drawable/ic_teamreview" /&gt;
  
                  &lt;ImageView
                      android:layout_width="126dp"
                      android:layout_height="wrap_content"
                      android:id="@+id/teambiosbtn"
                      android:background="@drawable/ic_teambios" /&gt;
  
                  &lt;ImageView
                      android:layout_width="119.5dp"
                      android:layout_height="wrap_content"
                      android:id="@+id/mentorsbtn"
                      android:background="@drawable/ic_mentor" /&gt;
  
                  &lt;ImageView
                      android:layout_width="127.5dp"
                      android:layout_height="wrap_content"
                      android:id="@+id/schedulebtn"
                      android:background="@drawable/ic_schedule" /&gt;
  
                  &lt;ImageView
                      android:layout_width="64dp"
                      android:layout_height="64dp"
                      android:id="@+id/twitterbtn"
                      android:background="@drawable/ic_twitter" /&gt;
  
                  &lt;ImageView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/profilebtn" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;ViewStub android:id="@+id/stub"
                  android:inflatedId="@+id/subTree"
                  android:layout_width="120dip"
                  android:layout_height="40dip" /&gt;
  
          &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>and here is the manifest</p>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.pixel.deloitte.xprizeapplication"&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="XPrize"
          android:supportsRtl="true"
          android:largeHeap="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".Dashboard"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>