“找不到或加载主类”是什么意思?

本文翻译自:What does “Could not find or load main class” mean?

A common problem that new Java developers experience is that their programs fail to run with the error message: Could not find or load main class ... 新Java开发人员遇到的一个常见问题是他们的程序无法运行并显示错误消息: Could not find or load main class ...

What does this mean, what causes it, and how should you fix it? 这是什么意思,是什么原因造成的,以及应该如何解决?


#1楼

参考:https://stackoom.com/question/1Dv3Y/找不到或加载主类-是什么意思


#2楼

The java <class-name> command syntax java <class-name>命令语法

First of all, you need to understand the correct way to launch a program using the java (or javaw ) command. 首先,您需要了解使用java (或javaw )命令启动程序的正确方法。

The normal syntax 1 is this: 常规语法1是这样的:

    java [ <option> ... ] <class-name> [<argument> ...]

where <option> is a command line option (starting with a "-" character), <class-name> is a fully qualified Java class name, and <argument> is an arbitrary command line argument that gets passed to your application. 其中<option>是命令行选项(以“-”字符开头), <class-name>是标准Java类名称,而<argument>是传递给应用程序的任意命令行参数。
1 - There is a second syntax for "executable" JAR files which I will describe at the bottom. 1-我将在底部描述“可执行” JAR文件的第二种语法。

The fully qualified name (FQN) for the class is conventionally written as you would in Java source code; 按照惯例,该类的全限定名(FQN)就像在Java源代码中一样; eg 例如

    packagename.packagename2.packagename3.ClassName

However some versions of the java command allow you to use slashes instead of periods; 但是,某些版本的java命令允许您使用斜杠代替句点。 eg 例如

    packagename/packagename2/packagename3/ClassName

which (confusingly) looks like a file pathname, but isn't one. 哪个(令人困惑)看起来像文件路径名,但不是一个。 Note that the term fully qualified name is standard Java terminology ... not something I just made up to confuse you :-) 请注意,术语“ 完全限定名”是标准的Java术语……不是我刚刚编造出来的,以使您感到困惑:-)

Here is an example of what a java command should look like: 这是一个java命令应如下所示的示例:

    java -Xmx100m com.acme.example.ListUsers fred joe bert

The above is going to cause the java command to do the following: 以上将导致java命令执行以下操作:

  1. Search for the compiled version of the com.acme.example.ListUsers class. 搜索com.acme.example.ListUsers类的编译版本。
  2. Load the class. 加载课程。
  3. Check that the class has a main method with signature , return type and modifiers given by public static void main(String[]) . 检查该类是否具有main方法,该方法具有public static void main(String[])给出的签名返回类型修饰符 (Note, the method argument's name is NOT part of the signature.) (请注意,方法参数的名称不是签名的一部分。)
  4. Call that method passing it the command line arguments ("fred", "joe", "bert") as a String[] . 调用该方法,以String[]将命令行参数(“ fred”,“ joe”,“ bert”)传递给它。

Reasons why Java cannot find the class Java找不到类的原因

When you get the message "Could not find or load main class ...", that means that the first step has failed. 当您收到消息“找不到或加载主类...”时,表明第一步已失败。 The j

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值