method must call super() error in Netbeans

倖福魔咒の 提交于 2019-11-26 12:48:32

问题


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, method: <init> signature: ()V) Constructor must call super() or this()
Could not find the main class: pie.chart.explorer.PieChartExplorer. Program will exit.
Exception in thread \"main\" Java Result: 1

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\");

            }
        }
    }

}

I have tried:

  1. Clean and Rebuild project
  2. Making sure that I have called super in all constructors

How can this be fixed? Code for download.


回答1:


I saw these symptoms just the other day.

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.

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

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

There are 2 ways to fix this:

  1. Rename "x/y/backup/Z.java" to "x/y/backup/Z.java.backup". (Prevent the backup copy from being compiled.)
  2. Change the package in "x/y/backup/Z.java" from "x.y" to "x.y.backup". (Make the backup create a different class file.)

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.

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




回答2:


I found that renaming the package did not work, the old package was still there.

The problem for me started when I copied a package from another application into the current application, which already had a package with the same name. I was trying to add some missing classes to the package. After I did that, the error started.

To resolve it, I deleted the entire package from the target web app and did a clean and build. Then I copied the source package into the target application. No errors.




回答3:


Cleaning and Building solves the problem




回答4:


If you still have the problem, this is how I solved it..

In my case I changed the class with main method later and the initial class was still referenced in the proporties file.

Change that setting, clean and build.. It worked for me...




回答5:


In my case, i had the same problem in a Web application after making an external copy of a POJO and manually editing it outside NETBEANS. The problem actually was what the others suggested in other answers about a conflict in the already compiled .class files.

What i did to overcome this was simply delete the folder webAppname/WEB-INF/classes (where compiled classes reside) and then do a Clean and Build

Hope this helps someone



来源:https://stackoverflow.com/questions/6560988/method-must-call-super-error-in-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!