@Override注解问题 [英] Problem with @Override annotation

查看:230
本文介绍了@Override注解问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作与Banko applet类似的Java应用程序.当我点击"public void init()"方法时,我运行得很好.当我完成后,除此以外的所有内容都已编译.它告诉我添加一个@Override注释.我尝试过,但是无论做什么,无论放置在哪里,编译器都会失败,并显示以下错误:

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:

找不到符号

符号:类覆盖

位置:类aBomb.Bomb

location: class aBomb.Bomb

我不知道是什么导致应用程序无法正常执行. :| 如果您在我在下面编写的代码中发现您认为应该更改的内容,请告诉我.我对Java比较陌生:( 代码:

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.)

我猜你有一个名为aBomb的类,它是从Applet扩展的:

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() {
//...
};

该错误消息看起来就像您将@Override拼写为@Overrides一样.

The error message looks as if you misspelled @Override as @Overrides.

这篇关于@Override注解问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆