Could not find main class HelloWorld

后端 未结 10 1750
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 09:39

I installed Java 1.7.0 in the following folder C:\\Program Files\\Java. My operating system is Windows XP(Version 2002) with Service pack 3.

The envir

相关标签:
10条回答
  • 2020-12-01 10:01

    You either want to add "." to your CLASSPATH to specify the current directory, or add it manually at run time the way unbeli suggested.

    0 讨论(0)
  • 2020-12-01 10:01

    I have also faced same problem....

    Actually this problem is raised due to the fact that your program .class files are not saved in that directory. Remove your CLASSPATH from your environment variable (you do no need to set classpath for simple Java programs) and reopen cmd prompt, then compile and execute.

    If you observe carefully your .class file will save in the same location. (I am not an expert, I am also basic programer if there is any mistake in my sentences please ignore it :-))

    0 讨论(0)
  • 2020-12-01 10:03

    Tell it where to look for you class: it's in ".", which is the current directory:

    java -classpath . HelloWorld
    

    No need to set JAVA_HOME or CLASSPATH in this case

    0 讨论(0)
  • 2020-12-01 10:04

    I had the same problem. Perhaps, the problem is that you have compiled and executed the class with different Java versions.

    Make sure the version of the compiler is the same as the command "java":

    javac -version
    
    java -version
    

    In Linux, use

    sudo update-alternatives --config java

    to change the version of Java.

    0 讨论(0)
提交回复
热议问题