Results 1 to 12 of 12

Thread: Compiles but java.lang.NoClassDefFoundError when I try to run it

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Compiles but java.lang.NoClassDefFoundError when I try to run it

    When I compile my code, I do this :

    Code:
    C:\Program Files\Java\jdk1.5.0\bin>javac c:\java\hello.java
    But when I go to run the class file I get the following error :

    Code:
    C:\Program Files\Java\jdk1.5.0\bin>java c:\java\hello
    Exception in thread "main" java.lang.NoClassDefFoundError: c:\java\hello
    The code I have made (very advanced ):

    Code:
    class Hello {
    	public static void main(String [] args) {
    		System.out.println("Hello world");
    	}
    }
    Any ideas?

    Thanks


    Has someone helped you? Then you can Rate their helpful post.

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    Originally posted by manavo11
    The code I have made (very advanced ):
    Just got mine running.

    I suggest you put the directory of your java exes to your Path Environment Variables. By this, you can javac, java on all directories you are in.

    edit: Or just set your classpath to c:\java and simple java Hello.
    Last edited by brown monkey; Oct 22nd, 2004 at 10:00 PM.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Usage:
    java [options] classname
    "c:\java\hello" is not the classname, it's the path of your class file with the .class stripped. That's different, very different.
    Correct would be
    java -classpath="%CLASSPATH%;c:\java\" hello
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    And %CLASSPATH% being the enviromental variable? How do I set that? I create it myself?


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    I dont know what os you are running but since i am running win98 i just open the System Configuration Editor and change the AutoExec.bat file.

  6. #6
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    Originally posted by manavo11
    And %CLASSPATH% being the enviromental variable? How do I set that? I create it myself?
    I'm guessing you are using 2000, which I don't know. Hehehe. This is what I did in my XP time machine.

    - Right click My Computer then Properties
    - Advanced Tab
    - Environment Variables
    - System Variables then New
    - Variable name: classpath, Variable value: c:\java;some_directory...
    - Ok, Ok then Ok.

    Hope this helps. If not, sorry.

  7. #7

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    I have XP so I'll try what you said BM Thanks


    Has someone helped you? Then you can Rate their helpful post.

  8. #8

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by brown monkey
    I'm guessing you are using 2000, which I don't know. Hehehe. This is what I did in my XP time machine.

    - Right click My Computer then Properties
    - Advanced Tab
    - Environment Variables
    - System Variables then New
    - Variable name: classpath, Variable value: c:\java;some_directory...
    - Ok, Ok then Ok.

    Hope this helps. If not, sorry.
    Hmmm, is version 5 needed?

    Registry key 'Software\JavaSoft\Java Runtime Environment\CurrentVersion'
    has value '1.4', but '1.5' is required.
    Error: could not find java.dll
    Error: could not find Java 2 Runtime Environment.


    Has someone helped you? Then you can Rate their helpful post.

  9. #9
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    I don't know if this helps but did you install the Java Runtime? You have the sdk 1.5 and you are using the Runtime 1.4. It requires the 1.5 Runtime, I guess.

  10. #10

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Actually I don't know what I am doing I had installed version 5, then my teacher gave me 1.4.2 to use so I don't even know what I have anymore


    Has someone helped you? Then you can Rate their helpful post.

  11. #11
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    What is your classpath environment variable set to? If you have already set it, and you think it's correct but it's still not running the program, you can usually add .;%classpath%.; at the begining of your classpath and it will work.

  12. #12

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Thanks I'll try it when I get home


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

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



Click Here to Expand Forum to Full Width