Search code examples
javaswingnetbeanschartssuperclass

method must call super() error in Netbeans


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.


Solution

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