Forum Stats

  • 3,875,872 Users
  • 2,266,977 Discussions
  • 7,912,361 Comments

Discussions

EXCEPTION IN THREAD "MAIN" java.lang.NoClassDef

843810
843810 Member Posts: 46,938
I am getting this error whenever i try to execute a java program.....

I have setted the environment variables as follows:

Classpath: C:\Program Files\Java\jdk1.5.0\bin;.;C:\Program Files\Java\jdk1.5.0\lib;.;C:\Program Files\Java\jdk1.5.0\lib\dt.jar;.;

path: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Java\jdk1.5.0\bin;C:\Program Files\Java\jdk1.5.0\lib

I am requesting you to provide a solution for the exception and to handle the error....Thanks in advance

Comments

  • 843810
    843810 Member Posts: 46,938
    Paste the whole exception, the small part You presented tells nothing, excepting the fact that there is a lack of some class.
  • 843810
    843810 Member Posts: 46,938
    exception in thread 'main' java.lang.NoClassDefFound Error: Sample/java

    I have created the simple java program named "Sample" and .java as an extension in notepad.
    This program is saved as a notepad in

    C:\Documents and Settings\***\My Documents\Java (Here, JAVA is the folder created so as to save the java programs)
  • 843810
    843810 Member Posts: 46,938
    Did You name the file Sample.java? Check out the extension of the file cause sometimes it happens that notepad adds .txt at the end (Sample.java.txt) - if so, the compiler message is correct, there's no Sample.java. Also pay attention to the content of the Sample.java file. In the most basic form it should be:
    public class Sample {}
    The name of the class must be the same as the name of file (case sensitive!).
  • 843810
    843810 Member Posts: 46,938
    The following code is the implementation of Sample.java program and i checked its extension too. That is Sample.java.txt


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


    I am here providing the path where i installed Java: C:\Program Files\Java\jdk1.5.0

    After the installation i have got two folders in JAVA: jdk 1.5.0 and jre 1.5.0

    I have included only jdk files such as lib, bin and dt.jar in class path of environmental variables.

    Here i am again posting the settings:

    CLASSPATH: C:\Program Files\Java\jdk1.5.0\bin;.;C:\Program Files\Java\jdk1.5.0\lib;.;C:\Program Files\Java\jdk1.5.0\lib\dt.jar;

    PATH:%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Java\jdk1.5.0\bin;C:\Program Files\Java\jdk1.5.0\lib;.;C:\Program Files\Java\jdk1.5.0\lib;.;C:\Program Files\Java\jdk1.5.0\lib\dt.jar;

    Thank you for your reply
  • 843810
    843810 Member Posts: 46,938
    The following code is the implementation of Sample.java program and i checked its extension too. That is Sample.java.txt


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


    I am here providing the path where i installed Java: C:\Program Files\Java\jdk1.5.0

    After the installation i have got two folders in JAVA: jdk 1.5.0 and jre 1.5.0

    I have included only jdk files such as lib, bin and dt.jar in class path of environmental variables.

    Here i am again posting the settings:

    CLASSPATH: C:\Program Files\Java\jdk1.5.0\bin;.;C:\Program Files\Java\jdk1.5.0\lib;.;C:\Program Files\Java\jdk1.5.0\lib\dt.jar;

    PATH:%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Java\jdk1.5.0\bin;C:\Program Files\Java\jdk1.5.0\lib;.;C:\Program Files\Java\jdk1.5.0\lib;.;C:\Program Files\Java\jdk1.5.0\lib\dt.jar;

    Thank you for your reply
  • 843810
    843810 Member Posts: 46,938
    Your java configuration is ok, cause the compiler starts to work and results in error. As I said before the name of the file is incorrect, it should be Sample.java not Sample.java.txt. This is why the error occurs. Correct the name of the file, and then try again.
This discussion has been closed.