Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

  1. #1
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    Hiya, I am very new to all programming. Can anyone tell me why the below will not run? I have set the classpath in control panel and have tried setting it first in command prompt. Its probably obvious, but I cannot find the answers on other forums. The simple.class file is in the same folder as the simple.java. Have tried with and without -classpath - i get a longer error without -classpath. Thanks.

    Microsoft Windows [Version 6.1.7600]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Scotty>javac D:\JAVA\simple.java

    C:\Users\Scotty>java -classpath . simple
    Exception in thread "main" java.lang.NoClassDefFoundError: simple
    Caused by: java.lang.ClassNotFoundException: simple
    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)
    Could not find the main class: simple. Program will exit.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,320
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    Where is the .class file created by the javac command? Is it in the same folder where you executed the java command?
    You told the javac command where the source file was.

  3. #3
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    Yes it is in the same folder. I have also tried just


    C:\Users\Scotty>javac D:\JAVA\simple.java

    C:\Users\Scotty>java simple
    Exception in thread "main" java.lang.NoClassDefFoundError: simple
    Caused by: java.lang.ClassNotFoundException: simple
    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)
    Could not find the main class: simple. Program will exit.

    In D:\JAVA is simple.java and simple.class
    Last edited by Scotty; October 4th, 2010 at 03:04 AM.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,320
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    In D:\JAVA is simple.java and simple.class
    But you are in a different folder, not the one with the simple.class file. Here you are in the Scotty folder:
    C:\Users\Scotty>java simple
    Change folders using the cd command to be in the Java folder, not the Scotty folder.

  6. #6
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    I see what you mean, but I cannot get it to change directory. Can you give me an example? I am obliviously doing something wrong.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,320
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    Use the cd command to change directories.
    cd THEDIR
    or cd ..

  8. #8
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    Sorry!

    C:\Users\Scotty>cd D:\JAVA

    C:\Users\Scotty>javac simple.java
    javac: file not found: simple.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Users\Scotty>javac D:\JAVA\simple.java

    C:\Users\Scotty>cd D:\JAVA\

    C:\Users\Scotty>java simple
    Exception in thread "main" java.lang.NoClassDefFoundError: simple
    Caused by: java.lang.ClassNotFoundException: simple
    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)
    Could not find the main class: simple. Program will exit.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,320
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    What folder is the simple.class file in? Use the dir command to show what files are in the current folder.
    If the simple.class file is NOT in your current folder, then the java command will not find it and you get the error.
    Use the cd command to change the current folder to the one with the simple.class file. Then java simple will work.

  10. The Following User Says Thank You to Norm For This Useful Post:

    Scotty (October 7th, 2010)

  11. #10
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    simple.class is in D:\JAVA

    (D:\JAVA\simple.class)

  12. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,320
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    Have you tried executing the java command when you are in the JAVA folder?
    Read post#9 again

  13. The Following User Says Thank You to Norm For This Useful Post:

    Scotty (October 7th, 2010)

  14. #12
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    Fixed it xD. It still ignores one of my directorys though....

  15. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,320
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    If you get errors, please post them here.

  16. #14
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)

    Quote Originally Posted by Scotty View Post
    Sorry!

    C:\Users\Scotty>cd D:\JAVA

    C:\Users\Scotty>javac simple.java
    javac: file not found: simple.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Users\Scotty>javac D:\JAVA\simple.java

    C:\Users\Scotty>cd D:\JAVA\

    C:\Users\Scotty>java simple
    Exception in thread "main" java.lang.NoClassDefFoundError: simple
    Caused by: java.lang.ClassNotFoundException: simple
    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)
    Could not find the main class: simple. Program will exit.
    Hey Scotty!

    --> C:\Users\Scotty>cd D:\JAVA

    This line won't take u to the D:\JAVA location. Instead, it will still be in C:\Users\Scotty.
    You need to first go into the D drive by giving

    C:\Users\Scotty>D:

    and then give the command "cd JAVA"

    Now that you are in the required folder. you can directly give

    "javac simple.java" followed by
    "java simple"

    It should solve the problem

Similar Threads

  1. Replies: 16
    Last Post: August 27th, 2010, 04:30 PM
  2. Replies: 2
    Last Post: March 26th, 2010, 12:22 PM
  3. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  4. Please help! Exception in thread "main" java.lang.NullPointerException
    By Arutha2321 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 18th, 2009, 02:25 AM
  5. Replies: 1
    Last Post: October 25th, 2009, 12:54 PM