Android app crashing and I cannot figure out why
<p>I have a very strange bug.  It only happens in the Emulator. I tested it on multiple Android phones and the Acer Tablet, it works fine there.</p>

<p>My program has a loop that loads in Bitmaps into a <code>Bitmap[] bitCards</code>. The Array is set up for 14 elements by <code>bitCards = new Bitmap[14]</code>.</p>

<p>Now it loops 12 times to put a Bitmap into the Array as follows:</p>

<pre><code>bitCards[i] = BitmapFactory.decodeStream(inputStream);
</code></pre>

<p>When i = 8 it crashes at this statement.</p>

<p>If i replace it with</p>

<pre><code>bitCards[0] = BitmapFactory.decodeStream(inputStream);
</code></pre>

<p>it does not crash, I thought maybe somehow the Array was not big enough so I did the following</p>

<pre><code>bitCards[8]=BitmapFactory.decodeStream(inputStream); // Still did not crash.
</code></pre>

<p>The only thing that makes sense is that when I have</p>

<pre><code>bitCards[i] = BitmapFactory.decodeStream(inputStream);
</code></pre>

<p>It is relasing the old memory and putting in a new object, thus only memory for one object is created, but.... the exception does not go off, shouldn't I get some kind of an error?</p>

<p>Here is my full code:</p>

<pre><code>void Shuffle()
{
    Random generator;
    generator = new Random();
    int[] iCardsUsed;
    iCardsUsed = new int[55];
    for(int i=0;i&lt;55;i++)
    iCardsUsed[i]=0;

    try {   

        bitCards = new Bitmap[14];
        iCards = new int[14];
        iTurnOver = new int[14];

        for (int i = 0; i &lt; 12; i++)
        {
            iTurnOver[i]=0;

            int cardId;

            do {
                cardId = generator.nextInt(50);
            } while( iCardsUsed[cardId] ==1);

            iCardsUsed[cardId] =1;
            iCards[i]=cardId;

            iCards[i]=i;    
            String fName=new String("card");
            fName+=Integer.toString(iCards[i]+1);
            fName+=".jpg";

            AssetManager assetManager= ctx.getAssets();
            InputStream inputStream;
            inputStream = assetManager.open(fName);

            // this is where it crashes
            bitCards[i]=BitmapFactory.decodeStream(inputStream);

            inputStream.close();    
        }

    } catch( IOException e)
    {
        gi++;
    }
    // update screen
    invalidate();
}
</code></pre>
