exception in thread 'main' java.lang.NoCla

2020-01-25 05:45发布

The following program is throwing error:

public class HelloWorld {
    public static void main(String args[]) {
        System.out.println("Hello World!"); 
    }
}

CLASSPATH C:\Program Files\Java\jdk1.6.0_18\bin\

Path C:\Program Files\Java\jdk1.6.0_18\bin\

JAVAHOME C:\Program Files\Java\jdk1.6.0_18\bin

Can you please tell me the root cause?

22条回答
对你真心纯属浪费
2楼-- · 2020-01-25 05:51

Had the same problem tried above solutions but none worked. I had to go through my java code only to find that the main function could not be recognised since there was no space btw it and (String) ie initial code:

public static void main(String[]args){

working code.

public static void main (String[]args){

Hope I helped someone.

查看更多
该账号已被封号
3楼-- · 2020-01-25 05:52

Easy & Simple solution: I solved this problem (NetBeans) by exporting the original project into zip file, deleting the original project directory and importing the project back from the zip file.

查看更多
你好瞎i
4楼-- · 2020-01-25 05:53

The Problem here is the setting the environment and the running of the class file. a. To set the environment path run the following command: set path=C:\Program Files (x86)\Java\jdk1.7.0\bin b. run the program from the package like com.test.TestJavaClass

Command: java com.test.TestJavaClass

The general issue here is we run it either from inside the package like src/package/name. We should not include src, package name is enough.

查看更多
We Are One
5楼-- · 2020-01-25 05:55

If your package is helloworld you would go to parent dir of your package then run:

java helloworld.HelloWorld
查看更多
Luminary・发光体
6楼-- · 2020-01-25 05:55

I had this proplem I used maven. I just click maven projects ant then name

project-> plugins -> clean -> and button run.

enter image description here

查看更多
兄弟一词,经得起流年.
7楼-- · 2020-01-25 06:00

The javadoc of NoClassDefFounError itself would be a good start (here), and then I'll suggest you clean and rebuild your project.

查看更多
登录 后发表回答