Results 1 to 8 of 8
  1. #1
    hamedy is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default Duplicate class error

    hi there,

    I'm a 1 day java programmer ! started with netbeans and right away faced a meaningless error:

    1- created a new empty project,
    2- added an empty java file to default package called GradeBook !
    3- put this in the file:
    public class GradeBook
    {
    public void displayMessage()
    {
    System.out.println("test");
    }
    }
    and it gives the error "duplicate class: GradeBook"
    when I change the name to anything else it gets right !
    please sb tell me what the hell is this :D

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Hmm, normally its caused by having another file with the class in it within the same package. Do you have two GradeBook classes somewhere? Maybe in another file? If not I did some reading on it and it seems that some times Netbeans doesn't always properly rebuild itself or something to that effect. They suggest deleting all the unnecessary old files and trying it again. They also said to try using the "Clean and Build" option, now I don't know what that does because I don't use Netbeans I assume it filters out whatever isn't necessary for the program to run.

    However since you're just starting, I suggest using a less helpful IDE. IDE's are helpful, too helpful in fact for people starting. While there are exceptions, it often allows the user to be lazy and take shortcuts instead of actually learning why certain things act the way they do. I suggest using Notepad++. It has a bunch of IDE functionality, the useful stuff like auto-indenting and syntax highlighting, without giving you so much power that you can easily skip out on the things you are trying to learn.

    Using Notepad++ and the Command Prompt to handle your Java building will force you to get your hands dirty and learn more about the language.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  3. #3
    hamedy is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    thanks for the reply,
    I tried almost all of them, even tried removing the whole project and directories on disk and recreating it, but it remains the same, also tried clean and build but no luck.
    actually I'm new in java but not in programming and have a little experience in .net programming and worked with MS Visual IDE and want a powerfull IDE to write java codes, I'm trying to find the problem and fix it not easily switching my IDE .
    btw, I don't have any duplicated file so maybe I should ask the question in netbeans section :D

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    Moved from 'New to Java' and locked the second thread.

    db

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    the "Clean and Build" option, now I don't know what that does
    It deletes the entire content of the build and dist folders (clean) and then regenerates them (build).

    db

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    Do some detective work. Use another class name, then in that class declare a variable of type GradeBook then right-click / 'Fix Imports'. See what class is imported. Of course, if there's really a duplicate class in a default package, that can't be imported.

    Check that you don't have unwanted stuff in your jre/lib/ext folder. Have you been saving any of your own work in that folder, or any folder under the jdk program folder?

    db

  7. #7
    hamedy is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    I tried removing the whole project and recreated it again and it worked this time, now I can't test your solution but I remember it for similar future problems,
    thank you

  8. #8
    cfsavant is offline Member
    Join Date
    Jun 2012
    Posts
    1
    Rep Power
    0

    Default Re: Duplicate class error

    Quote Originally Posted by hamedy View Post
    I tried removing the whole project and recreated it again and it worked this time, now I can't test your solution but I remember it for similar future problems,
    thank you
    I was getting this same issue with Jax-ws client. It was caused by a different build error. I cleaned up the code to remove the other build errors, but still had the duplicate class issue until I did a clean and build. I believe this is because this causes the Generated Source to be rebuilt.

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 10:04 PM
  2. Replies: 0
    Last Post: 03-27-2011, 05:49 AM
  3. Error if array contains duplicate integers
    By lithium002 in forum New To Java
    Replies: 4
    Last Post: 12-05-2009, 08:58 AM
  4. Replies: 3
    Last Post: 05-04-2009, 03:15 AM
  5. Error in class
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-09-2007, 04:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •