×

Loading...

I got an effor message saying "....java.lang.NoClassDefFoundError:...".

本文发表在 rolia.net 枫下论坛Q: I am trying to learn Java. I copied a Hello.java example to C:\sources and then succeeded in compiling the course file into the class file. Then, I tried to run this example by entering "java Hello". However, I got an effor message saying "....java.lang.NoClassDefFoundError:...". What's wrong?

A: Very probably, your Windows envirenment variable CLASSPATH does not include ".", --- the current directory. To execute your command "java Hello", Java Virtual Machine needs to search the class file Hello.class according to CLASSPATH. If it fails to find the class file, it will complain by throwing the message you cited. For a Java programmer, it is a good practice to include the current directory in the CLASSPATH.

To make your example work, you can reset the CLASSPATH by issuing

"set CLASSPATH=.;%CLASSPATH%"

in the MS-DOS. The above command means to append . (the current directory) to the CLASSPATH.

Note: Windowes envirment variable should be sandwished by a pair of percentage signs (%). After you reset the CLASSPATH, you will have luck to run your example.

PATH and CLASSPATH are two most basic environment variables for Java programmers. Even seasoned Java developers can get into dark with them. A Java novice needs to make many mistakes with them before mastering them.更多精彩文章及讨论,请光临枫下论坛 rolia.net
Sign in and Reply Report

Replies, comments and Discussions: