11

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.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Andrew delgadillo
  • 714
  • 6
  • 13
  • 24
  • Can you past full error message? Is there any file, class or line information? – Emre Yazici Jul 03 '11 at 03:51
  • @eyazici I included there error message in my edit. Please look at updated info – Andrew delgadillo Jul 03 '11 at 03:56
  • 1
    @Andrew: The error you posted looks like a runtime error. Are you getting build errors? Post details about the "duplicate class" error you've mentioned. – Gabe Jul 03 '11 at 04:01
  • Did you import the package that contains `Pie` class? After commenting `actionPerformed` method (because of Pie class) your code is compiled successfuly with javac-1.6.0_13. – Emre Yazici Jul 03 '11 at 04:03
  • @eyazici All of it worked fine before I started using the svn. – Andrew delgadillo Jul 03 '11 at 04:06
  • 2
    Your code that I have downloaded is fine. I wonder if you have multiple versions of your class files elsewhere or some other source code problem. I use SVN myself, so I'm not sure how to blame that, and can't if it's used correctly. – Hovercraft Full Of Eels Jul 03 '11 at 04:10
  • Concur with @Hovercraft Full Of Eels. Subversion is a red herring here. I tested your code both before and after importing it into a local SVN repo. It all continued to work, even after making changes, committing them, etc. I would suggest as a troubleshooting step to do a full clean and build, then run your code from a terminal (NB outputs the command at the end of the build). It's likely that the NB project got messed up when you did the SVN import (the NB/SVN integration isn't that great). – Mac Jul 03 '11 at 05:08
  • 1
    Are your class files under SVN control? If they are then they can easily get duplicated. Only source code files should be under SVN control. I know in NetBeans there are several files that control project properties maybe one of them contains an error. What about trying to import what you have to a new project? – adamjmarkham Jul 03 '11 at 06:25
  • My easiest solution is to back up, delete the offending java file and copy it back. See [Uncompilable Source Code after duplicate Copy](https://netbeans.org/bugzilla/show_bug.cgi?id=230497) – user250343 May 30 '13 at 06:24

5 Answers5

12

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.

downeyt
  • 131
  • 1
  • 3
11

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.

Devon_C_Miller
  • 16,248
  • 3
  • 45
  • 71
2

Cleaning and Building solves the problem

swapnil gandhi
  • 816
  • 1
  • 20
  • 38
1

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

0

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

MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125