简体   繁体   English

@Override注释出现问题

[英]Problem with @Override annotation

I am making a Java application similar to that of the Banko applet. 我正在创建一个类似于Banko applet的Java应用程序。 I was coming along just fine when I hit the "public void init()" method. 当我点击“public void init()”方法时,我的表现很好。 When I was finished, everything compiled except for that. 当我完成时,除了那之外所有编译。 It told me to add an @Override annotation. 它告诉我添加@Override注释。 I tried that, but whenever I do, regardless of where I put it, the compiler fails with the following error: 我试过了,但每当我这样做时,无论我把它放在哪里,编译器都会失败并出现以下错误:

cannot find symbol 找不到标志

symbol: class Overrides 符号:类覆盖

location: class aBomb.Bomb location:class aBomb.Bomb

I have no idea what could be preventing the application from executing properly. 我不知道什么可能阻止应用程序正常执行。 :| :| If you find something in the code I have written below that you think should be changed, please tell me. 如果您在下面写的代码中找到了您认为应该更改的内容,请告诉我。 I'm relatively new to Java :( Code: 我是Java的新手:(代码:

public void init() {
    BorderLayout border = new BorderLayout();
    setLayout(border);

    JPanel top = new JPanel();
    JLabel moneyLabel = new JLabel("Money : $");
    moneyField = new JTextField("", 8);
    moneyField.setEditable(false);
    JLabel foundLabel = new JLabel("Found: ");
    foundField = new JTextField("", 8);
    foundField.setEditable(false);

    restart = new JButton("Restart");
    restart.addActionListener(this);
    top.add(moneyLabel);
    top.add(moneyField);
    top.add(foundLabel);
    top.add(foundField);
    top.add(restart);
    add(top, BorderLayout.NORTH);

    board = new Board(this, ROW_COUNT, COLUMN_COUNT, BOMB_COUNT);
    add(board, BorderLayout.CENTER);
    setup();
    setVisible(true);
}

First of all, it would really help if you'd included at least the class definition (the "public class..." part.) 首先,如果您至少包含了类定义(“公共类......”部分),那将会非常有用

I'm guessing that you have a class named aBomb which extends from Applet: 我猜你有一个名为aBomb的类,它从Applet扩展而来:

public class aBomb extends Applet {
//...
    // Here's the init method; the @Override goes
    // immediately before the declaration.
    @Override
    public void init() {
//...
};

The error message looks as if you misspelled @Override as @Overrides . 该错误消息看起来好像您错误地将@Override拼写为@Overrides

The annotation class you are trying to use is java.lang.Override . 您尝试使用的注释类是java.lang.Override This is imported by default. 这是默认导入的。

Check the following: 检查以下内容:

  • The annotation is @Override but the error message says that you spelled it as @Overrides . 注释是@Override但错误消息表明您将其拼写为@Overrides Check your source code for a spelling / typing error. 检查源代码是否存在拼写/输入错误。

  • You are using Java 5.0 or later. 您正在使用Java 5.0或更高版本。

  • You have not used the -source or -target compilation switches to compile for an older version of Java. 您还没有使用-source-target编译开关来编译旧版本的Java。

  • You are not using -bootclasspath (or whatever) to compile against a non-standard class library. 您没有使用-bootclasspath (或其他)来编译非标准类库。

The annotation is called @Override , not @Overrides . 注释称为@Override ,而不是@Overrides It goes in front of the overriding method, like: 它走在最重要的方法面前,如:

@Override
public void init() {
   ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM