Android-IndexOutOfBound Exception
<p>I have wrote an adapter for the gridView to display photo which is download from internet and part of the code is listed as follow</p>

<pre><code>public class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;
    private Context mContext;

    public ArrayList&lt;Drawable&gt; drawablesFromUrl = new ArrayList&lt;Drawable&gt;();

    public ImageAdapter(Context c) {
        mContext = c;

    }

    public void addItem(Drawable item) {
        drawablesFromUrl.add(item);
    }

    public int getCount() {
        return drawablesFromUrl.size();
    }

    public Drawable getItem(int position) {
        return drawablesFromUrl.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }

        imageView.setImageDrawable(drawablesFromUrl.get(position));
        return imageView;

    }//View getView

}//class ImageAdapter
</code></pre>

<p>It work properly and the downloaded photo was stored in the ArrayList "drawablesFromUrl.get(position)"</p>

<p>Now I have wrote an intent to open another activity to shown an individual photo in the imagView and part of the code is list as follow:</p>

<pre><code>SitePhotoGallery pg = new SitePhotoGallery();
    ImageAdapter imageAdapter = pg.new ImageAdapter(this);

    Drawable dPhoto=imageAdapter.drawablesFromUrl.get(position); //(ERROR in this line)
    BitmapDrawable bPhoto  = (BitmapDrawable) dPhoto;
    Bitmap snoop = bPhoto.getBitmap();

    //Bitmap snoop = BitmapFactory.decodeResource(getResources(),imageAdapter.mThumbIds[position]);
    img.setImageBitmap(snoop);  
    img.setMaxZoom(4f);        
    setContentView(img);     
</code></pre>

<p>It prompt an error : 
07-11 15:22:11.458: E/AndroidRuntime(12856): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.mcsis/com.android.mcsis.SitePhotoFullScreen}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0</p>

<p>I guess the arraylist "imageAdapter.drawablesFromUrl.get(position);" is empty, anything I got wrong?</p>

<p>Thanks for your help....</p>
