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);
}
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:
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
.
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.
The annotation is called @Override
, not @Overrides
. It goes in front of the overriding method, like:
@Override
public void init() {
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.