方法必须在Netbeans中调用super()错误 [英] method must call super() error in Netbeans

查看:474
本文介绍了方法必须在Netbeans中调用super()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我做了一个Netbeans项目,我一起使用SVN。我看到重复的类错误,并在控制台中表示

Recently I've made a Netbeans project and I am using SVN along with it. I am seeing duplicate class error, and in the console it says

java.lang.VerifyError:(class:pie / chart / explorer / PieChartExplorer ,方法:< init> signature:()V)构造函数必须调用super()或this()

找不到主类:pie.chart.explorer.PieChartExplorer。程序将退出。

线程main中的异常Java结果:1

这里是PieChartExplorer.java: / p>

Here is PieChartExplorer.java:

package pie.chart.explorer;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class PieChartExplorer extends JFrame implements ActionListener {


    JTextField one = new JTextField(10);
     JTextField two = new JTextField(10);
      JTextField three = new JTextField(10);
    JButton sub = new JButton("Click to be amazed");


    public PieChartExplorer() {
        super("Pie Chart Explorer");
        setSize(300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        FlowLayout flo = new FlowLayout();
        setLayout(flo);
        setVisible(true);
        add(one);
        add(two);
        add(three);
        sub.addActionListener(this);;
        add(sub);

    }

    public static void main(String[] args) {
        PieChartExplorer app = new PieChartExplorer();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();

        if(source == sub) {
            try {
            Pie show = new Pie(Float.parseFloat(one.getText()),Float.parseFloat(two.getText()),Float.parseFloat(three.getText()));
            } catch(Exception ex) {
                JOptionPane.showMessageDialog(this, "Please check entered data");

            }
        }
    }

}

我尝试过:


  1. 清理并重建项目

  2. 我在所有构造函数中调用了super。

如何修复? 下载代码

推荐答案

我在另一天才看到这些症状。

I saw these symptoms just the other day.

如果我的文件我一直在编辑,并决定我想把我的更改分成2提交。我去了包含我的文件x / y / Z.java的目录,在x / y名为备份的目录,移动Z.java在那里,并从版本控制拉新的副本。

I had I file I had been editing and decided I wanted to split my changes into 2 commits. I went to the directory containing my file "x/y/Z.java", made a directory in "x/y" named "backup", moved "Z.java" there, and pulled a fresh copy from version control. Note all of this was done outside the IDE.

回到IDE中,我在第一次提交的更改中合并,当我构建I获取Z.java的重复类消息。

Back in the IDE I merged in the changes for the first commit and when I built I got the duplicate class message for "Z.java".

当我将源代码复制到备份时,我在IDE外部做了,它仍然有原始包 xy,我新编辑的Z.java。 NB不会编译新的Z.java,因为它可以看到它已经创建了xyZclass(从x / y / backup / Z.java)。

When I copied the source to "backup" I did it outside the IDE and it still had the original package "x.y" as did my newly edited "Z.java". NB would not compile the new "Z.java" because it could see it had already created "x.y.Z.class" (from "x/y/backup/Z.java").

有2种方法可以解决此问题:

There are 2 ways to fix this:


  1. 将x / y / backup / Z.java重命名为x / y /backup/Z.java.backup。 (防止备份副本被编译。)

  2. 将x / y / backup / Z.java中的包从x.y更改为x.y.backup (使备份创建不同的类文件。)

执行任何更改后,执行清理和构建。 注意:只是构建无法解决问题,您需要执行清除以删除恶意类文件。

After making either of these changes, perform a "clean and build". Note: simply building will not fix the problem, you need to perform a clean to remove the rogue class file.

#1是通过从命令行重命名Z.java完成的,而不是在NB中。 NB不会让您更改文件扩展名。

Note: #1 was done by renaming Z.java from the command line, not within NB. NB will not let you change the file extension.

这篇关于方法必须在Netbeans中调用super()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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