源代码如下:
public class Snake {
public static final int UP=0;
public static final int DOWN=1;
public static final int LEFT=2;
public static final int RIGHT=3;
public int direction;
private LinkedList<Point> body=new LinkedList<Point>();
private Set<SnakeListener> listeners=new HashSet<SnakeListener>();

public void Snake(){
init();
}
public void init(){
int x=Globall.WIDTH/2;
int y=Globall.HEIGHT/2;
for(int i=0;i<3;i++){
body.addFirst(new Point(x--,y));

direction=RIGHT;
}
public void move(){
//去尾
body.removeLast();

int x=body.getFirst().x;
int y=body.getFirst().y;
switch(direction){
case UP:
y--;
break;
case DOWN:
y++;
break;
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
}
Point newHead=new Point();
//加头
body.addFirst(newHead);
System.out.println("Snake's move");
}
    public void changeDirection(int direction){
     this.direction=direction;
     System.out.println("Snake's changeDirection");
    }
    public void eatFood(){
     System.out.println("Snake's eatFood");
    }
    public boolean isEatBody(){
     System.out.println("Snake's isEatBody");
     return false;
    }
    public void drawMe(Graphics g){
     System.out.println("Snake's drawMe");
    
     g.setColor(Color.BLUE);
     for(Point p:body){
     g.fill3DRect(p.x*Globall.CELL_SIZE, p.y*Globall.CELL_SIZE
     , Globall.WIDTH, Globall.HEIGHT, true);
     }
    }
    private class SnakeDriver implements Runnable{ @Override
public void run() {
// TODO Auto-generated method stub
while(true){
move();

for(SnakeListener l:listeners){
l.snakeMoved(Snake.this);//内部类
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
    
    }
    public void start(){
     new Thread(new SnakeDriver()).start();
    }
    
    public void addSnakeListener(SnakeListener l){
     if(l!=null){
     this.listeners.add(l);
     }
    }
}异常如下:
Exception in thread "Thread-3" java.util.NoSuchElementException
at java.util.LinkedList.remove(Unknown Source)
at java.util.LinkedList.removeLast(Unknown Source)
at china.snake.my.Snake.move(Snake.java:35)
at china.snake.my.Snake$SnakeDriver.run(Snake.java:84)
at java.lang.Thread.run(Unknown Source)
怎样解决啊?初学者不会啊!