Page 1 of 2 12 LastLast
Results 1 to 20 of 30
  1. #1
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default strange error in eclipse

    Hey everyone.

    I'm trying to write a simple program but I keep getting the following error:

    Exception in thread "main" java.lang.NoClassDefFoundError: Main
    Caused by: java.lang.ClassNotFoundException: Main
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)


    and here is the code:

    class apples{
    public static void main(String args[]){
    int test=6;

    if (test==9){
    System.out.println("yes");

    }
    else{
    System.out.println("No");
    }
    }
    }



    Thanks in advance!

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, your "class" is "apples", not Main, so edit the run configuration to call the proper class.

  3. #3
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default

    I'm not sure I understand. I just need to change apples to main? why's that? I thought you could make up a name for the class?

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    You can call the class anything you like. (Within reason, and it is best to start with a capital letter).

    The point masijade was making is that you have to tell Eclipse to run the class you mean it to. And not a class called Main which is what you are doing at the moment.

  5. #5
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default

    Alright I changed the class to Apples and everything works fine and dandy. Why is it that it can't be called main though?

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by stevenpalomino View Post
    Alright I changed the class to Apples and everything works fine and dandy. Why is it that it can't be called main though?
    You can call a class (almost) everything you want but you have to tell Eclipse exactly that name if you want to run it; you called your class 'apples' but you told Eclipse that it had to run a class named 'Main'; that, of course, doesn't make sense and the JVM told you so: it couldn't find a class named 'Main'. Eclipse can do a lot for you but it can't corrrect your mental mistakes you made.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default

    Hello everyone,

    Here's another weird error I'm getting. Does this make sense to anyone?
    Thanks in advance!


    Exception in thread "main" java.io.IOException: No such file or directory
    at java.io.UnixFileSystem.createFileExclusively(Nativ e Method)
    at java.io.File.createNewFile(File.java:883)
    at ContactFileDAO.loadContacts(ContactFileDAO.java:19 )
    at Menu.<init>(Menu.java:13)
    at ContactBook.main(ContactBook.java:10)

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    "No such file or directory"

    How is that weird? It makes perfect sense to me.

  9. #9
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default

    but I don't have a thread named "main"?

  10. #10
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Yes you do. All programs have at least one thread.

    "ContactFileDAO.java:19"

    This is where your problem is. On that line you are doing something with a file that does not exist or at least not where your Java program is looking for it.

    Java Code:
    System.out.println(FFFF.getAbsolutePath());
    After you change FFFF to the name of your variable add that line to your program above the line causing the error and you will find out where your program is trying to find your file.

  11. #11
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default

    This is line 19. Doesn't really tell me anything :S
    file.createNewFile();

  12. #12
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default

    Here is the program. Anyone find a problem?
    Thanks!

    Jasons Address Book.zip

  13. #13
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    And what is "file" defined as? What is the path that that File object refers to and does that path exist, and do you have permission to write there? If you look at the stacktrace pointed above you will see the call to that method. Come on, you have got to be able to analyse problems better than this.

  14. #14
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default

    I'm sorry I'm new to Java. I had a friend send me an example file so that I could study it but I couldn't get it to run. I saw this:

    Java Code:
    File file = new File(dir + FILE_NAME);
    		file.createNewFile();
    But I'm not sure what I'm supposed to do with it. Sorry I'm not that great at troubleshooting. I'm new to it. Thanks for your help though!

  15. #15
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    And what are "dir" and "FILE_NAME" defined as? And does concating them like this lead to a proper a path? Or is the file separator missing between them? As already suggested use println to print the value of the path.

    Edit: P.S. this is what comes of blindly copying code with no understanding of what it does. Example code should be used as nothing more than a nudge in the (hopefully) right direction, it should not be cut-n-pasted.

  16. #16
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default

    There's also this next snippet of code right after it:

    Java Code:
    Scanner fileReader = new Scanner(file);
    		Contacts contacts = new Contacts();
    Should that make it work or do I actually need to replace "dir" and "FILE_NAME" with something?

    EDIT* Also, my friend just told me he wrote the code on windows and since I'm on a Mac there might have to be a few changes. What should be different?
    Last edited by stevenpalomino; 06-21-2011 at 06:34 PM.

  17. #17
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    I'm sorry, buht I'm out of here.

  18. #18
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default

    ok Thanks anyway.

  19. #19
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by stevenpalomino View Post
    Should that make it work or do I actually need to replace "dir" and "FILE_NAME" with something?

    EDIT* Also, my friend just told me he wrote the code on windows and since I'm on a Mac there might have to be a few changes. What should be different?
    dir+FILE_NAME should result in a sensible (potential) file name. Why not print it just before you attempt to create a file:

    Java Code:
    System.out.println(dir+FILE_NAME);
    Do you see anything on your console? Does it make sense? Can you 'manually' create a file with that name?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  20. #20
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default

    ah. it says C:/contacts.txt. how would I change that to a Mac relevant system?

Page 1 of 2 12 LastLast

Similar Threads

  1. BufferedReader throwing strange error
    By DragonGhola in forum Advanced Java
    Replies: 4
    Last Post: 06-16-2011, 11:17 AM
  2. Strange Compilation Error About Generics
    By dhafirnz in forum Advanced Java
    Replies: 7
    Last Post: 11-16-2010, 09:54 AM
  3. Strange Error
    By AJArmstron@aol.com in forum New To Java
    Replies: 1
    Last Post: 04-18-2010, 10:31 PM
  4. Strange eclipse behaviour with new version
    By KingOfLions in forum Eclipse
    Replies: 0
    Last Post: 09-10-2009, 02:42 PM
  5. strange Error message
    By little_polarbear in forum New To Java
    Replies: 4
    Last Post: 08-26-2008, 12:45 AM

Posting Permissions

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