Buggy code:
public class SnakeView extends TileView { private static final String TAG = "SnakeView" ; private int mMode = SnakeView . READY ; public static final int PAUSE = 0 ; public static final int READY = 1 ; public static final int RUNNING = 2 ; public static final int LOSE = 3 ; private int mDirection = SnakeView . NORTH ; private int mNextDirection = SnakeView . NORTH ; private static final int NORTH = 1 ; private static final int SOUTH = 2 ; private static final int EAST = 3 ; private static final int WEST = 4 ; private static final int RED_STAR = 1 ; private static final int YELLOW_STAR = 2 ; private static final int GREEN_STAR = 3 ; private long mScore = 0 ; private long mMoveDelay = 600 ; private long mLastMove ; private TextView mStatusText ; private ArrayList < SnakeView . Coordinate > mSnakeTrail = new ArrayList < SnakeView . Coordinate > ( ) ; private ArrayList < SnakeView . Coordinate > mAppleList = new ArrayList < SnakeView . Coordinate > ( ) ; private static final Random RNG = new Random ( ) ; private SnakeView . RefreshHandler mRedrawHandler = new SnakeView . RefreshHandler ( ) ; class RefreshHandler extends Handler { @ Override public void handleMessage ( Message msg ) { } public void sleep ( long delayMillis ) { } } public SnakeView ( Context context , AttributeSet attrs ) { } public SnakeView ( Context context , AttributeSet attrs , int defStyle ) { } private void initSnakeView ( ) { } private void initNewGame ( ) { } private int [ ] coordArrayListToArray ( ArrayList < SnakeView . Coordinate > cvec ) { } public Bundle saveState ( ) { } private ArrayList < SnakeView . Coordinate > coordArrayToArrayList ( int [ ] rawArray ) { } public void restoreState ( Bundle icicle ) { } public void MessageBox ( String message ) { } @ Override public boolean onTouchEvent ( MotionEvent msg ) { } @ Override public boolean onKeyDown ( int keyCode , KeyEvent msg ) { } public void setTextView ( TextView newView ) { } public void setMode ( int newMode ) { } private void addRandomApple ( ) { } public void update ( ) { } private void updateWalls ( ) { } private void updateApples ( ) { } private void updateSnake ( ) { boolean growSnake = false ; SnakeView . Coordinate head = mSnakeTrail . get ( 0 ) ; SnakeView . Coordinate newHead = new SnakeView . Coordinate ( 1 , 1 ) ; mDirection = mNextDirection ; switch ( mDirection ) { case SnakeView . EAST : { newHead = new SnakeView . Coordinate ( ( ( head . x ) + 1 ) , head . y ) ; break ; } case SnakeView . WEST : { newHead = new SnakeView . Coordinate ( ( ( head . x ) - 1 ) , head . y ) ; break ; } case SnakeView . NORTH : { newHead = new SnakeView . Coordinate ( head . x , ( ( head . y ) - 1 ) ) ; break ; } case SnakeView . SOUTH : { newHead = new SnakeView . Coordinate ( head . x , ( ( head . y ) + 1 ) ) ; break ; } } if ( ( newHead . x ) < 1 ) { newHead . x = ( mXTileCount ) - 2 ; } if ( ( newHead . x ) > ( ( mXTileCount ) - 2 ) ) { newHead . x = 1 ; } if ( ( newHead . y ) < 1 ) { newHead . y = ( mYTileCount ) - 2 ; } <START_BUG> if ( ( newHead . y ) > ( ( myTileCount ) - 2 ) ) { <END_BUG> newHead . y = 1 ; } int snakelength = mSnakeTrail . size ( ) ; for ( int snakeindex = 0 ; snakeindex < snakelength ; snakeindex ++ ) { SnakeView . Coordinate c = mSnakeTrail . get ( snakeindex ) ; if ( c . equals ( newHead ) ) { return ; } } int applecount = mAppleList . size ( ) ; for ( int appleindex = 0 ; appleindex < applecount ; appleindex ++ ) { SnakeView . Coordinate c = mAppleList . get ( appleindex ) ; if ( c . equals ( newHead ) ) { mAppleList . remove ( c ) ; addRandomApple ( ) ; ( mScore ) ++ ; mMoveDelay *= 0.9 ; growSnake = true ; } } mSnakeTrail . add ( 0 , newHead ) ; if ( ! growSnake ) { mSnakeTrail . remove ( ( ( mSnakeTrail . size ( ) ) - 1 ) ) ; } int index = 0 ; for ( SnakeView . Coordinate c : mSnakeTrail ) { if ( index == 0 ) { setTile ( SnakeView . YELLOW_STAR , c . x , c . y ) ; } else { setTile ( SnakeView . RED_STAR , c . x , c . y ) ; } index ++ ; } } private class Coordinate { public int x ; public int y ; public Coordinate ( int newX , int newY ) { } public boolean equals ( SnakeView . Coordinate other ) { } @ Override public String toString ( ) { } } }

Fix:
if ( ( newHead . y ) > ( ( mYTileCount ) - 2 ) ) {