Java 我一直收到一个错误;解析时已到达文件末尾";

Java 我一直收到一个错误;解析时已到达文件末尾";,java,Java,这个编译器错误(重要的是要指定它不是运行时错误)几乎总是意味着您在某个地方丢失了一个关闭的大括号-在这种情况下,看起来您丢失了关闭类的大括号(在源代码的底部) 如果您想要更友好地记录错误,可以将其视为编译器说“我在关闭所有作用域块之前到达了文件末尾。”解析什么?可能“slurp.wav:和“fanfare.wav”未找到或无效。因为您在类的末尾缺少}? import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /

这个编译器错误(重要的是要指定它不是运行时错误)几乎总是意味着您在某个地方丢失了一个关闭的大括号-在这种情况下,看起来您丢失了关闭类的大括号(在源代码的底部)


如果您想要更友好地记录错误,可以将其视为编译器说“我在关闭所有作用域块之前到达了文件末尾。”

解析什么?可能“slurp.wav:和“fanfare.wav”未找到或无效。因为您在
类的末尾缺少
}
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)

/**
 * This class defines a crab. Crabs live on the beach. They like sand worms 
 * (very yummy, especially the green ones).
 * 
 * Version: 4
 * 
 * The crab is keyboard controlled and eats worms. In this version, we have added
 * a sound when the crab eats a worm.
 */

public class Crab extends Actor
{

    private GreenfootImage image1;
    private GreenfootImage image2;
    private int age;

    /**
     * Create a crab and initialize its two images.
     */
    public Crab()
    {
        image1 = new GreenfootImage("crab.png");
        image2 = new GreenfootImage("crab2.png");
        setImage(image1);
    }
    /** 
     * Act - do whatever the crab wants to do. This method is called whenever
     *  the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        boolean isAlive;
        int n;
        checkKeypress();
        move(5);
        lookForWorm();
        if ( getImage() == image1)
        {setImage(image2);
        }
        else
        {
            setImage(image1);
        }

    }

    /**
     * Check whether a control key on the keyboard has been pressed.
     * If it has, react accordingly.
     */
    public void checkKeypress()
    {
        if (Greenfoot.isKeyDown("up")) 
        {
            setLocation(getX(), getY()-4);
        }
        if (Greenfoot.isKeyDown("down")) 
        {
            setLocation(getX(), getY()+4);
        }
    }

    /**
     * Check whether we have stumbled upon a worm.
     * If we have, eat it. If not, do nothing.
     */
    public void lookForWorm()
    {
        if ( isTouching(Worm.class) ) 
        {
            removeTouching(Worm.class);
            Greenfoot.playSound("slurp.wav");

            wormsEaten = wormsEaten + 1;
            if (wormsEaten == 8)
            {
                Greenfoot.playSound("fanfare.wav");
                Greenfoot.stop();
            }
        }
    }