Getting error “cannot find or load main class HelloWorld”

前端 未结 3 1240
鱼传尺愫
鱼传尺愫 2021-01-22 20:05

I have this simple code:

public class HelloWorld{
    public static void main(String[] args){
        System.out.println(\"HelloWorld\");
    }
}
相关标签:
3条回答
  • 2021-01-22 20:22

    try: java -cp "C:\WhatEverDirectoryYourFileIsIn" HelloWorld

    0 讨论(0)
  • 2021-01-22 20:24

    You could get this behaviour if you have an incorrect / inappropriate setting of the CLASSPATH environment variable; e.g. the current directory isn't on the classpath. (It is by default ... )

    Try this:

    java -classpath . HelloWorld
    

    Assuming that works ... the problem is your understanding of the concept of the "classpath". This is explained well by the Oracle documentation:

    • The java & javac command documentation ... particular the -classpath argument
    • Setting the Classpath.
    • The Java Tutorial - PATH and CLASSPATH
    0 讨论(0)
  • 2021-01-22 20:34

    In CMD, instead of typing:

    java HelloWorld
    

    Try typing:

    java HelloWorld.class
    
    0 讨论(0)
提交回复
热议问题