Why does Exception in thread "main" appear when executing JAVA program

java.lang.NoClassDefFoundError wrong? … You
should check your environment and your operations like this:

  1. Is your file name correct?
    JAVA requires that your file and your class name strictly correspond.
    For example, public class HelloWorld {...
    then the file name must be only HelloWorld.java, look carefully!
  2. Is there a main method in your program? Is the parameter correct?
    The main method should be declared like this:
    public static void main (String [] args)
    In fact, if you do it with development tools, it will not be wrong. If you use UltraEdit or something to write a program, just copy it without changing it!
  3. Remember, the parameter followed by javac is the file name, but java is followed by the class name!
    This is the mistake I made when I started learning Java, java HelloWorld.class, and then reported an error. Later, I realized that it should be java HelloWorld.
  4. Is the classpath set?
    Not only is the content to be set when installing the JDK, it is generally best to set up a directory to store your own class files. For example, the d: \ class directory.
    Set classpath =% classpath%; d: \ class
    Then, now copy the HelloWorld.class file to the d: \ class directory, then java HelloWorld should be OK.
  5. Combining points 3 and 4
    If your class belongs to a certain package, such as such a class sony.test.HelloWorld, then according to the directory I said in point 4, you should put HelloWorld.class file Store in the d: \ class \ sony \ test \ directory.
    When executing, you should refer to point 3 and execute by class name: java sony.test.HelloWorld.

do you understand? I can't think of any reason why this error message can be caused! If any brother thinks of it, just add it!
In fact, if you use some better programming tools, there is no chance to encounter this error. At least after I used VisualAge for Java, there is no such thing.
Okay, don't say it, I wish comrades good luck!
After this first door, the latter is relatively simple!

Published 17 original articles · praised 0 · visits 217

Guess you like

Origin blog.csdn.net/neheqi/article/details/105379899
Recommended