title: Throwing OutOfMemoryError "Failed to allocate a 18485292 byte allocation with 15229320 free bytes and 14MB until OOM"
body: <p>I have this error in one activity a bout out of memory : </p>
  
  <blockquote>
    <p>Process: com.moments.hamza.babytalk, PID: 16463
                                                                                java.lang.OutOfMemoryError: Failed to allocate a 18485292 byte allocation with 15230424 free bytes and 14MB until OOM
                                                                                    at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                                    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                                                    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:747)
                                                                                    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:568)
                                                                                    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014)
                                                                                    at android.content.res.Resources.loadDrawableForCookie(Resources.java:3747)
                                                                                    at android.content.res.Resources.loadDrawable(Resources.java:3620)
                                                                                    at android.content.res.TypedArray.getDrawable(TypedArray.java:762)
                                                                                    at android.widget.ImageView.(ImageView.java:151)
                                                                                    at android.widget.ImageView.(ImageView.java:140)
                                                                                    at android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:57)
                                                                                    at android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:53)
                                                                                    at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:102)
                                                                                    at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:972)
                                                                                    at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1030)
                                                                                    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
                                                                                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
                                                                                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
                                                                                    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
                                                                                    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
                                                                                    at com.moments.hamza.babytalk.Level_2.onCreate(Level_2.java:49)
                                                                                    at android.app.Activity.performCreate(Activity.java:6283)
                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
                                                                                    at android.app.ActivityThread.access$900(ActivityThread.java:177)
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                    at android.os.Looper.loop(Looper.java:145)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5942)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)</p>
  </blockquote>
  
  <p>the xml layout file : </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="match_parent"
      tools:context="com.moments.hamza.babytalk.Level_2"
      android:padding="16dp"&gt;
  
  
      &lt;ViewFlipper
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/v_f_level2"
          android:layout_marginBottom="50dp"
          android:layout_alignParentEnd="true"
          android:layout_alignParentStart="true"&gt;
  
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_aid"
              android:src="@drawable/letter_a"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_bid"
              android:src="@drawable/letter_b"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_cid"
              android:src="@drawable/letter_c"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_did"
              android:src="@drawable/letter_d"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_eid"
              android:src="@drawable/letter_e"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_fid"
              android:src="@drawable/letter_f"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_gid"
              android:src="@drawable/letter_g"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_hid"
              android:src="@drawable/letter_h"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_iid"
              android:src="@drawable/letter_i"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_jid"
              android:src="@drawable/letter_j"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_kid"
              android:src="@drawable/letter_k"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_lid"
              android:src="@drawable/letter_l"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_mid"
              android:src="@drawable/letter_m"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_nid"
              android:src="@drawable/letter_n"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_oid"
              android:src="@drawable/letter_o"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_pid"
              android:src="@drawable/letter_p"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_qid"
              android:src="@drawable/letter_q"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_rid"
              android:src="@drawable/letter_r"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_sid"
              android:src="@drawable/letter_s"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_tid"
              android:src="@drawable/letter_t"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_uid"
              android:src="@drawable/letter_u"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_vid"
              android:src="@drawable/letter_v"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_wid"
              android:src="@drawable/letter_w"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_xid"
              android:src="@drawable/letter_x"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_yid"
              android:src="@drawable/letter_y"
              android:scaleType="centerCrop" /&gt;
          &lt;ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/letter_zid"
              android:src="@drawable/letter_z"
              android:scaleType="centerCrop"
              android:contentDescription="@string/a_letter" /&gt;
  
      &lt;/ViewFlipper&gt;
  
      &lt;ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/next_level_2"
          android:src="@drawable/next"
          android:layout_alignParentBottom="true"
          android:layout_alignParentEnd="true" /&gt;
  
      &lt;ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/back_level_2"
          android:src="@drawable/back"
          android:layout_alignTop="@+id/next_level_2"
          android:layout_alignParentStart="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>the main code for level_2 is : </p>
  
  <pre><code>public class Level_2 extends AppCompatActivity {
  private ImageView back_level_2;
  private ImageView next_level_2;
  
  private ImageView letteraj;
  private ImageView letterbj;
  private ImageView lettercj;
  private ImageView letterdj;
  private ImageView letterej;
  private ImageView letterfj;
  private ImageView lettergj;
  private ImageView letterhj;
  private ImageView letterij;
  private ImageView letterjj;
  private ImageView letterkj;
  private ImageView letterlj;
  private ImageView lettermj;
  private ImageView letternj;
  private ImageView letteroj;
  private ImageView letterpj;
  private ImageView letterqj;
  private ImageView letterrj;
  private ImageView lettersj;
  private ImageView lettertj;
  private ImageView letteruj;
  private ImageView lettervj;
  private ImageView letterwj;
  private ImageView letterxj;
  private ImageView letteryj;
  private ImageView letterzj;
  
  private ViewFlipper v_f_level2j;
  private TextToSpeech t1;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_level_2);
  
      v_f_level2j = (ViewFlipper) findViewById(R.id.v_f_level2);
  
      back_level_2 = (ImageView) findViewById(R.id.next_level_2);
      next_level_2 = (ImageView) findViewById(R.id.back_level_2);
  
      letteraj=(ImageView) findViewById(R.id.letter_aid);
      letterbj=(ImageView) findViewById(R.id.letter_bid);
      lettercj=(ImageView) findViewById(R.id.letter_cid);
      letterdj=(ImageView) findViewById(R.id.letter_did);
      letterej=(ImageView) findViewById(R.id.letter_eid);
      letterfj=(ImageView) findViewById(R.id.letter_fid);
      lettergj=(ImageView) findViewById(R.id.letter_gid);
      letterhj=(ImageView) findViewById(R.id.letter_hid);
      letterij=(ImageView) findViewById(R.id.letter_iid);
      letterjj=(ImageView) findViewById(R.id.letter_jid);
      letterkj=(ImageView) findViewById(R.id.letter_kid);
      letterlj=(ImageView) findViewById(R.id.letter_lid);
      lettermj=(ImageView) findViewById(R.id.letter_mid);
      letternj=(ImageView) findViewById(R.id.letter_nid);
      letteroj=(ImageView) findViewById(R.id.letter_oid);
      letterpj=(ImageView) findViewById(R.id.letter_pid);
      letterqj=(ImageView) findViewById(R.id.letter_qid);
      letterrj=(ImageView) findViewById(R.id.letter_rid);
      lettersj=(ImageView) findViewById(R.id.letter_sid);
      lettertj=(ImageView) findViewById(R.id.letter_tid);
      letteruj=(ImageView) findViewById(R.id.letter_uid);
      lettervj=(ImageView) findViewById(R.id.letter_vid);
      letterwj=(ImageView) findViewById(R.id.letter_wid);
      letterxj=(ImageView) findViewById(R.id.letter_xid);
      letteryj=(ImageView) findViewById(R.id.letter_yid);
      letterzj=(ImageView) findViewById(R.id.letter_zid);
  
      t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
          @Override
          public void onInit(int status) {
              if(status != TextToSpeech.ERROR) {
                  t1.setLanguage(Locale.UK);
  
              }
          }
      });
      letteraj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="A";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterbj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="B";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      lettercj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="C";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterdj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="D";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterej.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="E";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterfj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="F";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      lettergj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="G";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterhj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="H";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterij.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="I";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterjj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="J";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterkj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="K";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterlj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="L";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      lettermj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="M";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letternj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="N";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letteroj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="O";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterpj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="P";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterqj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="Q";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterrj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="R";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      lettersj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="S";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      lettertj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="T";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letteruj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="U";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      lettervj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="V";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterwj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="W";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak, TextToSpeech.QUEUE_ADD, null);}});
      letterxj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="X";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letteryj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="Y";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
      letterzj.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String toSpeak ="Z";
              t1.setSpeechRate((float) 1);
              t1.speak(toSpeak,TextToSpeech.QUEUE_ADD, null);}});
  
  
  
  
  
      next_level_2.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              v_f_level2j.showNext();
          }
  
      });
  
  
      back_level_2.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              v_f_level2j.showPrevious();
          }
  
      });
  
  }
  }
  </code></pre>
  
  <p>can you please help me  ? </p>