Results 1 to 4 of 4
  1. #1
    PatHastings is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Exception in thread "main" error. [SOLVED]

    So I'm working off the book "Sams Teach Your Self Java 6 in 21 Days" and didnt make it very far... God JDK7 installed and was able to compile the "HelloUser" script
    Java Code:
    public class HelloUser {
    	public static void main(String[] arguments) {
    		String username = System.getProperty("user.name");
    		System.out.println("Hello " + username);
    	}
    }
    with no problem, but when I go to run it i get...

    Java Code:
    d:\Projects\Java\Source\HelloUser>java -cp . hellouser
    Exception in thread "main" java.lang.NoClassDefFoundError: hellouser (wrong name
    : HelloUser)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$100(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
    
    d:\Projects\Java\Source\HelloUser>
    I've tried just about every solution I can find and cant seem to get the thing running, I also tried other scripts on the web and cant get those to work either.
    I've tried changing the classpath to ".;C:\Program Files\Java\jdk1.7.0_04\lib\tools.jar;" I've also tried blank.
    any ideas??
    Thank
    -PatHastings
    Last edited by PatHastings; 06-06-2012 at 09:45 PM. Reason: solved

  2. #2
    PatHastings is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Re: Exception in thread "main" error.

    Never mind..... was typing "java hellouser", but supposed to be "java HelloUser" haha

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Exception in thread "main" error. [SOLVED]

    Are you calling

    java hellouser

    rather than

    java HelloUser

    ? Capitalization matters.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. Replies: 6
    Last Post: 01-21-2012, 05:59 AM
  2. Replies: 3
    Last Post: 09-11-2011, 09:15 AM
  3. Replies: 5
    Last Post: 06-22-2010, 03:51 PM
  4. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  5. Replies: 1
    Last Post: 08-07-2007, 07:10 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
  •