Results 1 to 4 of 4
  1. #1
    JavaNoob1998 is offline Member
    Join Date
    Apr 2011
    Posts
    4
    Rep Power
    0

    Unhappy Problem with first program...

    Dear all,

    A few hours ago I tried my first java program, as a complete noob, and after I fixed a typo in my code, thanks to one of the guys here, it compiled with javac under Mac OS X. I became a .class file and tried to run it by typing "java filename.class" and received the following error:


    Exception in thread "main" java.lang.NoClassDefFoundError: ILoveJava/class
    Caused by: java.lang.ClassNotFoundException: ILoveJava.class
    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)


    What couldve gone wrong here? Or should I say, where did I go wrong?

    Heres a summary of the steps.

    1) type in code in jedit
    2) compile in terminal on a macbook with javac filename.java
    3) obtain a .class file
    4) run it by typing "java filename.class"
    5) error msg listed above

    Thanks in advance!
    -The Noob

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    dont type ".class", just the program name and see. if you type ".class" the program thinks that your class is called 'class' in the package ILoveJava so it wont find your class file.

  3. #3
    JavaNoob1998 is offline Member
    Join Date
    Apr 2011
    Posts
    4
    Rep Power
    0

    Default

    I thought i'd paste the code, see if it helps.


    class ILoveJava {
    public static void main(String[] args) {
    System.out.println("I Love Java!");
    }
    }

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,413
    Rep Power
    20

    Default

    4) run it by typing "java filename.class"
    Bookmark this page
    http://download.oracle.com/javase/tu...ems/index.html

    You'll find solutions to all your early problems there, and in pages linked from it.

    db

Similar Threads

  1. what is the problem in this program ?????
    By sahildave1991 in forum AWT / Swing
    Replies: 1
    Last Post: 06-29-2010, 01:36 PM
  2. Problem in Program
    By Abbinormal in forum New To Java
    Replies: 9
    Last Post: 01-08-2010, 03:38 AM
  3. Problem with the below program
    By srikanthnambu in forum Java 2D
    Replies: 1
    Last Post: 05-20-2009, 05:43 PM
  4. Gui program problem..
    By mingming2009 in forum Advanced Java
    Replies: 7
    Last Post: 04-03-2009, 05:15 AM
  5. Program problem
    By arindamchkrbrty in forum New To Java
    Replies: 8
    Last Post: 03-10-2009, 04:58 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
  •