title: ImageView setsetImageResource keeps crashing on phone but not on emulator or tablet
body: <p>Developing a poker game, where I have 5 cards displayed initially with back of a card. Then will display the first set with new images of a card and still okay. Upon drawing for another card, the <code>setImageResource()</code> triggered <code>InvocationTargetException</code> while <code>debugging</code> using phone. And when running in phone, it crashed with <code>IllegalStateException</code> could not execute method for android <code>onClick()</code>. Sometimes it crashed on the second card, or 3rd or 4th card. No pattern. I don't encounter this using <code>emulator</code> or my <code>tablet</code>. Happening only on my 2 phones. Any help is greatly appreciated.</p>
  
  <pre><code>07-23 18:59:52.967 11643-11643/com.seanwilliam.pokersingle E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.seanwilliam.pokersingle, PID: 11643
  java.lang.IllegalStateException: Could not execute method for android:onClick
      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
      at android.view.View.performClick(View.java:5619)
      at android.view.View$PerformClick.run(View.java:22298)
      at android.os.Handler.handleCallback(Handler.java:754)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:165)
      at android.app.ActivityThread.main(ActivityThread.java:6365)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:883)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
   Caused by: java.lang.reflect.InvocationTargetException
      at java.lang.reflect.Method.invoke(Native Method)
      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
      at android.view.View.performClick(View.java:5619) 
      at android.view.View$PerformClick.run(View.java:22298) 
      at android.os.Handler.handleCallback(Handler.java:754) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:165) 
      at android.app.ActivityThread.main(ActivityThread.java:6365) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:883) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 
   Caused by: java.lang.OutOfMemoryError: Failed to allocate a 26269068 byte allocation with 3836592 free bytes and 3MB until OOM
      at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
      at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
      at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:624)
      at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:457)
      at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1152)
      at android.content.res.ResourcesImpl.createFromResourceStream(ResourcesImpl.java:1272)
      at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:743)
      at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:585)
      at android.content.res.MiuiResourcesImpl.loadDrawable(MiuiResourcesImpl.java:308)
      at android.content.res.Resources.getDrawable(Resources.java:785)
      at android.content.Context.getDrawable(Context.java:534)
      at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:358)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
      at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
      at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:85)
      at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:93)
      at com.seanwilliam.pokersingle.MainActivity.Draw(MainActivity.java:207)
      at com.seanwilliam.pokersingle.MainActivity.btnChange(MainActivity.java:98)
      at java.lang.reflect.Method.invoke(Native Method) 
      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384) 
      at android.view.View.performClick(View.java:5619) 
      at android.view.View$PerformClick.run(View.java:22298) 
      at android.os.Handler.handleCallback(Handler.java:754) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:165) 
      at android.app.ActivityThread.main(ActivityThread.java:6365) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:883) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 
  
  
      int[] imgCard = [R.drawable.c_ac, R.drawable.c_ad, R.drawable.c_ah, R.drawable.c_as,
          R.drawable.c_2c, R.drawable.c_2d, R.drawable.c_2h, R.drawable.c_2s,
          R.drawable.c_3c, R.drawable.c_3d, R.drawable.c_3h, R.drawable.c_3s,
          R.drawable.c_4c, R.drawable.c_4d, R.drawable.c_4h, R.drawable.c_4s,
          R.drawable.c_5c, R.drawable.c_5d, R.drawable.c_5h, R.drawable.c_5s,
          R.drawable.c_6c, R.drawable.c_6d, R.drawable.c_6h, R.drawable.c_6s,
          R.drawable.c_7c, R.drawable.c_7d, R.drawable.c_7h, R.drawable.c_7s,
          R.drawable.c_8c, R.drawable.c_8d, R.drawable.c_8h, R.drawable.c_8s,
          R.drawable.c_9c, R.drawable.c_9d, R.drawable.c_9h, R.drawable.c_9s,
          R.drawable.c_10c, R.drawable.c_10d, R.drawable.c_10h, R.drawable.c_10s,
          R.drawable.c_jc, R.drawable.c_jd, R.drawable.c_jh, R.drawable.c_js,
          R.drawable.c_qc, R.drawable.c_qd, R.drawable.c_qh, R.drawable.c_qs,
          R.drawable.c_kc, R.drawable.c_kd, R.drawable.c_kh, R.drawable.c_ks];
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  
      card1= (ImageView) findViewById(R.id.card1);
      card2= (ImageView) findViewById(R.id.card2);
      card3= (ImageView) findViewById(R.id.card3);
      card4= (ImageView) findViewById(R.id.card4);
      card5= (ImageView) findViewById(R.id.card5);
  
      hold1= (ImageView) findViewById(R.id.hold1);
      hold2= (ImageView) findViewById(R.id.hold2);
      hold3= (ImageView) findViewById(R.id.hold3);
      hold4= (ImageView) findViewById(R.id.hold4);
      hold5= (ImageView) findViewById(R.id.hold5);
  
  }
  
  
  public void btnChange(View view) {
      if (bDeal) {
          NewDeal();
      }else {
          Draw();
      }
      bDeal= ! bDeal;
  }
  
  
  
  public void NewDeal (){
  
      hold1.setVisibility(View.INVISIBLE);
      hold2.setVisibility(View.INVISIBLE);
      hold3.setVisibility(View.INVISIBLE);
      hold4.setVisibility(View.INVISIBLE);
      hold5.setVisibility(View.INVISIBLE);
  
      card1.setImageResource(R.drawable.c_blue_back);
      card2.setImageResource(R.drawable.c_blue_back);
      card3.setImageResource(R.drawable.c_blue_back);
      card4.setImageResource(R.drawable.c_blue_back);
      card5.setImageResource(R.drawable.c_blue_back);
  
  
          cardNo[0]=-1;
          cardNo[1]=-1;
          cardNo[2]=-1;
          cardNo[3]=-1;
          cardNo[4]=-1;
  
          GenerateCards();
  
          bHold1 =false;bHold2 =false;bHold3 =false;bHold4 =false;bHold5 =false;
          sKind[0]="";sKind[1]="";sKind[2]="";sKind[3]="";sKind[4]="";
          iCard[0]=0;iCard[1]=0;iCard[2]=0;iCard[3]=0;iCard[4]=0;
          int iC1, iC2, iC3, iC4, iC5;
          iC1=cardNo[0];
          iC2=cardNo[1];
          iC3=cardNo[2];
          iC4=cardNo[3];
          iC5=cardNo[4];
  
          card1.setImageResource(imgCard[iC1]);
          card2.setImageResource(imgCard[iC2]);
          card3.setImageResource(imgCard[iC3]);
          card4.setImageResource(imgCard[iC4]);
          card5.setImageResource(imgCard[iC5]);
  
  }
  
  
  public void Draw () {
      if (!bHold1) {
          cardNo[0] = -1;
      }
      if (!bHold2) {
          cardNo[1] = -1;
      }
      if (!bHold3) {
          cardNo[2] = -1;
      }
      if (!bHold4) {
          cardNo[3] = -1;
      }
      if (!bHold5) {
          cardNo[4] = -1;
      }
  
      //Get random number
      GenerateCards();
  
      //bHold1 =false;bHold2 =false;bHold3 =false;bHold4 =false;bHold5 =false;
      sKind[0] = "";
      sKind[1] = "";
      sKind[2] = "";
      sKind[3] = "";
      sKind[4] = "";
      iCard[0] = 0;
      iCard[1] = 0;
      iCard[2] = 0;
      iCard[3] = 0;
      iCard[4] = 0;
      int iC1, iC2, iC3, iC4, iC5;
      iC1 = cardNo[0];
      iC2 = cardNo[1];
      iC3 = cardNo[2];
      iC4 = cardNo[3];
      iC5 = cardNo[4];
  
      if (!bHold1) {
          card1.setImageResource(imgCard[iC1]);    &lt;--sometimes this is the error
      }
  
      if (!bHold2) {
          card2.setImageResource(imgCard[iC2]); &lt;--sometimes this is the error
      }
  
      if (!bHold3) {
          card3.setImageResource(imgCard[iC3]); &lt;--sometimes this is the error
      }
  
      if (!bHold4) {
          card4.setImageResource(imgCard[iC4]); &lt;--sometimes this is the error
      }
  
      if (!bHold5) {
              card5.setImageResource(imgCard[iC5]);
      }
  
  
  }
  </code></pre>