@Override 注解的问题
我正在制作一个类似于 Banko 小程序的 Java 应用程序。当我点击“public void init()”方法时,我进展顺利。当我完成后,除此之外的所有内容都已编译完毕。它告诉我添加 @Override 注释。我尝试过,但每当我这样做时,无论我把它放在哪里,编译器都会失败并出现以下错误:
找不到符号
符号:类覆盖
位置:类aBomb.Bomb
我不知道什么可能会阻止应用程序正确执行。 :| 如果您在我下面编写的代码中发现您认为应该更改的内容,请告诉我。我对 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);
}
I am making a Java application similar to that of the Banko applet. I was coming along just fine when I hit the "public void init()" method. When I was finished, everything compiled except for that. It told me to add an @Override annotation. 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
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:
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,如果您至少包含类定义(“公共类...”部分),那将真正有帮助。
我猜您有一个名为 aBomb 的类,它扩展了来自 Applet:
错误消息看起来好像您将
@Override
拼写为@Overrides
。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:
The error message looks as if you misspelled
@Override
as@Overrides
.您尝试使用的注释类是
java.lang.Override
。这是默认导入的。检查以下内容:
注释是
@Override
,但错误消息表明您将其拼写为@Overrides
。检查源代码是否存在拼写/输入错误。您正在使用 Java 5.0 或更高版本。
您尚未使用
-source
或-target
编译开关来针对旧版本的 Java 进行编译。您没有使用
-bootclasspath
(或其他内容)来针对非标准类库进行编译。The annotation class you are trying to use is
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
. Check your source code for a spelling / typing error.You are using Java 5.0 or later.
You have not used the
-source
or-target
compilation switches to compile for an older version of Java.You are not using
-bootclasspath
(or whatever) to compile against a non-standard class library.该注释称为
@Override
,而不是@Overrides
。它位于重写方法之前,例如:The annotation is called
@Override
, not@Overrides
. It goes in front of the overriding method, like: