Java first time

xiaoxiao2021-03-06  42

Last night, I successfully run my first Java program. Very excited, for the first time. The excitement is still a little to remind yourself or just start Java learning from Java.

In fact, last night I have successfully compiled HelloWorld (most classic procedures, all my programming languages ​​are starting from her), but the following error appears when running:

Exception in thread "main" java.lang.nosuchmethoderror: HelloWord / Class

What is the reason? I am online search solution to search for the following article:

Ask the people who have a HelloWorld issue is too much, and often start with "ask a simple question". its

Recalling, I have come from this stage, saying "Hello", is really a simplest problem.

? ... // Think is good, the words retired, let's say "HelloWorld!" in java ...

First of all, we have to assume that our platform is Windows JDK (the Linux environment is almost almost). This environment

It is quite common, foundation, and entry. Determine the JDK that has been installed correctly, the next step is to be carefully knocked into a teaching

The HelloWorld source code, store, then compile, Javac ... The problem is coming:

* Error 1:

'Javac' is not internal or external commands, nor is it runable or batch files.

(Javac: Command Not Found)

The reason is that no environment variable path is set. Add Path =% Path% under AutoExce.bat; C: /JDK1.2/bin, then Under Control Panel -> System -> Advanced -> Environment Variables -> System Variables ... See? Double click on Path, add C: /JDK1.2/bin in the back. Of course, we assume that JDK is installed in a C: /JDK1.2 directory (a little Tang Yan?) ... It seems to restart the system to work ... (// know! // Tomato) Good, try again ! Javac HelloWorld

* Error 2:

HelloWorld Is An Invalid Option OR Argument.

Please, give a professional spirit, Java's source program is necessary to store .java file, and write all. Java.

OK, Javac HelloWorld.java (this time should I become?)

* Error 3:

HelloWorld.java: 1: Public Class HelloWorld Must Be Defined in a File Called

"HelloWorld.java".

Public class helloworld {

^

This problem is because your name is inconsistent with the name of the file. (Who said, clearly seeing people have such a written () OK, accurately, can define multiple classes in a Java source program, but the classes with public properties can have one, and the name of the file As a result. Also, the main method must put in this public class, so that Java (running) this class. Another thing is that the Java language is strictly sized, beginners should pay attention to it. Medium HelloWorld and HelloWorld think that it is different, so ... oh ... good, change, 嘻 ... ... javac helloworld.java ... (咦, what is there?) // Faint This It is compiled! Take a look at it is a HelloWorld.class? (Hehe .. pressing the book :) Java HelloWorld (!! I know, not java helloworld.class 哟) * Error 4:

Exception in thread "main" java.lang.noclassdefounderror: helloWorld huh, this is the famous classpath problem. In fact, class paths are the concepts in Java involved in the compilation process. ClassPath is to specify where to find the class, it is as simple as it is. Since our HelloWorld is not used in other (non-java.lang package) classes, there is no encounter when compiling. When running, you have to indicate where your class is. Workaround, you can run with the following command:

Java-ClassPath. HelloWorld "." The current directory. Of course, this is a bit trouble (it is "too much trouble"!), We can set the default classpath in the environment variable. Methods are set by the above settings. Set ClassPath to:

Classpath = .; c: /jdk1.2/lib/dt.jar; c: /jdk1.2/lib/tools.jar's two suggestions also

It is developed in the future. Java-ClassPath. HelloWorld (I don't want to learn Java again.)

* Error 5:

Exception in thread "main" java.lang.nosuchmethoderror: main

(// 咣) Don't, stick to it. Look at your code, the problem is in the definition of the main method, write it to the place,

Is this written?

Public static void main (string args []) {// one word should not be poor, don't ask why ...

Yes, including case yours!

Java-ClassPath. HelloWorld (Listen to the heavens!)

Hello World!

(Faint! Finally ...)

Welcome to the Java world! Therefore, it is not a "simplest problem" that cannot be running helloworld is really a "simplest problem".

Attached: HelloWorld.java

// HelloWorld.java

Public class helloworld {

Public static void main (string args []) {

System.out.println ("Hello World!");

}

Haha finds the crux, wrong 5, but the author mentioned the mistake I have not failed, what should I do? I saw it for a long time, I finally found that I was running Java HelloWorld, in order to save things, I am in entering "Java Hel ...", in order to save things, directly press the TAB button, can think about the command to become this : "Java HelloWorld.class" So there is a prompt in the prompt, because Java can't bring a suffix when it is compiled .class file (this is me later, I don't know), this thing makes me Understand: The more the most detachable problems are easily neglected, and such negligence is the most difficult to discover, so the writing program must put the heart in the most easily ignored place. Write down this article to remind yourself and friends like me, I hope that there will be no longer have such a negligence in the future. (This may be deadly)

转载请注明原文地址:https://www.9cbs.com/read-59659.html

New Post(0)