Fixed a bug causing ArrayIndexOutOfBounds errors in ImageAdapter