Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: Newbie question about basic code - "Hello World"

  1. #1
    Kimomaru is offline Member
    Join Date
    Sep 2011
    Posts
    4
    Rep Power
    0

    Default Newbie question about basic code - "Hello World"

    I'm working through Java Examples in a Nushell and the first example includes syntax that I would like to understand better. Really basic;

    package je3.basics;
    public class Hello {
    public static void main (String [] args) {
    System.out.println ("Hello World");
    }
    }


    It compiles but it generates exceptions. I get this error;

    c:\JFiles\Java Examples in a Nutshell\Chapter 1>java Hello
    Exception in thread "main" java.lang.NoClassDefFoundError: Hello (wrong name: je
    3/basics/Hello)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n 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(Unkno wn Source)



    I know enough about this that if I remove the package syntax that it will work fine, but the book makes the point that adding prefixes in the long run is a good idea since it helps avoid naming conflicts. Cool. Why doesn't it run?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Newbie question about basic code - "Hello World"

    DarrylBurke likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Kimomaru is offline Member
    Join Date
    Sep 2011
    Posts
    4
    Rep Power
    0

    Default Re: Newbie question about basic code - "Hello World"

    Thanks, Kevin. I figured it out but couldn't post until now (the forums have been running slow this morning, I think.) Thank you for the reply.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Newbie question about basic code - "Hello World"

    No problem. The forums have been slow for me as well.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 6
    Last Post: 03-19-2011, 08:10 PM
  2. Replies: 24
    Last Post: 06-21-2010, 05:49 PM
  3. Replies: 3
    Last Post: 06-07-2009, 01:14 AM
  4. String greeting = "Hello, world!";
    By Gregorius in forum Introductions
    Replies: 2
    Last Post: 01-24-2009, 02:12 AM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 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
  •