Run Java program under cmd

Source: Internet
Author: User

I have been developing Java for a long time, but most of them are B/S development, which should be released to the Web server for running. On this day, a friend said that he had written a small game in Java and asked me to show it. If he had taken the source file and put it in eclipse for next compilation and running, there was no problem at all, then he added a Record ranking function and sent it back. But he said he couldn't run it?
Why? I ran to cmd, Java, mom, and so on. The error message about the class and main function could not be found: exception
In thread "Main" Java. Lang. noclassdeffounderror, It's really silly to give the hacker! There are still a lot of problems with Google search. The following points come to light:

1. Is your file name correct?
Java requires that your file exactly match your class name.
For example, public class helloworld {.....
The file name must be helloworld. java. Check it carefully!

2. Do you have the main method in your program? Are the parameters correct?
The Declaration of the main method should be like this:
Public static void main (string [] ARGs)
In fact, if you use development tools, it will not be wrong. If you use ultraedit or another type to write a program, do not copy a word!

3. Remember, the parameters behind javac are file names, but those behind Java are class names!
This is what I made when I started learning java. Java helloworld. class, and then I will report an error. Later I realized that it should be Java helloworld.

4. Have you set classpath?
It is not only the content to be set during JDK installation, but also a directory to store your class files. For example, D: \ class directory.
Set classpath = % classpath %; D: \ class
Now copy the helloworld. Class file to the D: \ class directory, and then Java helloworld should be OK.

5. Combine points 3rd and 4th
If your class belongs to a certain package, such as Sony. test. helloworld, so according to the directory I mentioned in the 4th point, we should put helloworld. class files are stored in the D: \ class \ Sony \ test \ directory.
During execution, you should refer to the section 3rd "execute by Class Name: Java Sony. Test. helloworld.

According to the above 1.1 points, the error was found that the classpath parameter was not set at, and a long-overdue interface was immediately displayed, the gutter will also be overturned.

Article Reprinted from: http://hqs2892805.blog.163.com/blog/static/37996831201271341511436/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.