Results 1 to 5 of 5

Thread: Exception in thread "main" java.lang.NoClassDefFoundError:

  1. #1

    Thread Starter
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292

    Exception in thread "main" java.lang.NoClassDefFoundError:

    hello all,

    i am starting a introductory java course next week and thought it would be nice to at least try to write-compile-run a simple java program.

    here is my code
    Code:
    class fun {
     public static void main(String[] arguments) {
      // My first Java program goes here
      String greeting = "Hello World";
      System.out.println(greeting);
    
     }
    }
    for some reason it's not letting me run it

    after i installed the kit

    in dos i write
    java -version
    and it gave me
    java version "1.3.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1
    Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
    so i know that it can find the jdk1.3 folder

    so i went to the bin folder and compiled the above program

    javac c:\javafile\fun.java

    it worked since i had no message and a file was created on the same level called fun.class

    so then i tried to run it

    java c:\javafile\fun

    and this is the message i got


    C:\jdk1.3\bin>java c:\javafile\fun
    Exception in thread "main" java.lang.NoClassDefFoundError: c:\javafile\fun
    i then looked in the appendix and tried to add this line to my autoexc.bat file (i have win 98)

    SET CLASSPATH=%CLASSPATH%;.;C:\jdk1.3\lib\tools.jar;c:\jdk1.3

    the book said that this should fix my problem but i get still the same error

    can anyone tell me what i should check next?

    why does it let me compile but not run?

    help i'm stuck..


    bsw

  2. #2

    Thread Starter
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292
    found my mistake,

    i needed to run it from the same directory.
    i was fooled because to compile it i needed to be in jkd1.3\bin
    directory

    bsw

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    For java you don't specify paths on the command line. You specify which class to run, and classes don't care about paths.
    This is why you either need to be in the directory of the codebase or specify the directory of the codebase via the -classpath option.
    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

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    And you might want to add c:\jdk1.3\bin to your PATH in autoexec.bat. Then you can compile from everywhere.
    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.

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