Begineers Java Problem
Results 1 to 5 of 5

Thread: Begineers Java Problem

  1. #1
    Senior Member
    Join Date
    Feb 2005

    Begineers Java Problem


    I have started java language yesterday and i am unable to run my first program.

    I am following the book the complete reference of java by mc-graw hill.

    It told me to run the program from the dos mode by compiling it with javac as

    It did not work so i went into the directory of java and then into bin and executed javac from there.

    As expected a class Example1.class was created. I executed
    D:\Program Files>j2sdk_nb>j2sdk1.4.2>bin>javac D:\a\

    Files were stored in the folder a in the drive drive d:

    it compiled fine.

    Now i tried the java command and it gave an error which i am unable to understand.

    D:\Program Files>j2sdk_nb>j2sdk1.4.2>bin>java D:\a\Example1

    The error is:
    Exception in thread "main" java.lang.NoClassDefFoundError: D:\a\Example1

    Please help me
    i am unable to get the problem.

    What should i do
    \"The Smilie Wars\" ... just arrived after the great crusades

    .... computers come to the rescue .... ah technology at last has some use.

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Heres the code of the program

    class Example1
    { public static void main(String args[])
    { System.out.println("This ia a simple java program.");
    \"The Smilie Wars\" ... just arrived after the great crusades

    .... computers come to the rescue .... ah technology at last has some use.

  3. #3
    Elite Hacker
    Join Date
    Mar 2003
    Try cd'ing into the directory where the program is, then do this
    path=D:\Program Files\j2sdk_nb\j2sdk1.4.2\bin
    java Example1
    or get an ide that will compile and run for you. has a simple free one. Good luck.

  4. #4
    Senior Member
    Join Date
    Jul 2002
    Hmm, I had the exact same problem at my college , when they imaged the machines, they forgot to tell windows the correct classpath to find java. This sounds like your problem so here's how to fix it.

    *Right-click 'My Computer'
    *Select the 'Advanced' tab
    *Scroll down to the 'Environment Variables' button
    *Now notice the system variables pane...
    *Find the vaiable 'path' and hit edit
    *Now on the textfield where it says 'variable value' go all the way to the and add the directory location of javac.

    This is what mine looked like...
    Hit 'ok' and that should work for you. What your doing here is telling the computer where to look basically to compile. It does exactly what is posted above, just a different way. Perhaps slightly more confusing

    Note: for this solution I am assuming you are using Windows XP
    The real question is not whether peace can be obtained, but whether or not mankind is mature enough for it...

  5. #5
    AntiOnline n00b
    Join Date
    Feb 2004

    Yup I think THE RADICA got that Right .......But you are setting the path varible RADICA not the classpath...... Path tells where to look for the java compiler and as it's compiling fine i don't think path needs to be set........ Sounds to me like the Classpath is not right ......... happens to me all the time in the School Lab .......... In the Book you are reading try reading the Packages Chapter classpath generally explained there .......... In my school lab Students **** up the class path when they make their own packages ....... few Morons when adding their own Classpath are too lazy to add that %classpath% ...... they would simply say set classpath=c:\userdirocetry instead of Set Calsspath=%classpath%;c:\userdirocetry

    OK enough Ranting i guess ........ Coming to your Problem ....... Try Setting that Classpath manually at the Command Prompt.

    Somethig like

    Set classpath=%classpath%;.;

    then if dosen't work try this

    Set classpath=%classpath%;D:\Program File\j2sdk_nb\j2sdk1.4.2\lib;.;

    Assuming the path of your Lib Folder is that .

    You see at the end ;.; ...... that DOT means include Current Diroctary to the class path generally that's the problem.


    ooo Just out of Sheer curiocity is the Class File which has the main() method Same as the File name ? .... it also happens if you don't have them same.


Posting Permissions

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