简体   繁体   English

找不到或加载主类Java错误记事本++

[英]Could not find or load main class Java Error Notepad++

I've implemented "Java Compile" and "Compile and Run" (the second as Java Compile and Run) as described in this answer: Java compile and run using notepad++ and nppexec . 我已经按照此答案中的描述实现了“ Java编译”和“编译并运行”(第二个为Java编译并运行): Java使用notepad ++和nppexec进行编译和运行

Note: I'm using 1.8.0_20 rather than 1.7.0 as described in the answer. 注意:我使用的是1.8.0_20,而不是答案中所述的1.7.0。

However, when I try to run HelloWorld (as found here: http://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm ) to test the compiler, I get the following response, including a "Could not find or load main class" error: 但是,当我尝试运行HelloWorld(位于http://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm )以测试编译器时,得到以下响应,包括“找不到或加载主类”错误:

NPP_EXEC: "Java Compile and Run"
CD: C:\Users\Bova\Documents
Current directory: C:\Users\Bova\Documents
"C:\Program Files (x86)\Java\jdk1.8.0_20\bin\java" -classpath "C:\Users\Bova\Documents"    "HelloWorld"
Process started >>>
Error: Could not find or load main class HelloWorld
<<< Process finished. (Exit code 1)
================ READY ================

What do I need to change to avoid this error? 为了避免此错误,我需要更改什么?

The very first line of HelloWorld.java reads: HelloWorld.java第一行内容为:

package helloworld;

Java packages are mapped to directories on the filesystem, so the interpreter expects to find HelloWorld.class inside a helloworld directory. Java包被映射到文件系统上的目录,因此解释器希望在helloworld目录中找到HelloWorld.class Move the .class file to a helloworld subdir and run it as: .class文件移动到helloworld子目录,然后按以下方式运行它:

> java helloworld.HelloWorld

from the parent directory (ie the directory which contains helloworld/ ). 从父目录 (即包含helloworld/的目录)中。

I had this problem in Notepad++ too. 我在Notepad ++中也遇到了这个问题。 What I did to fix it was I went to the Plugins menu, clicked on NppExec, and selected Follow $(CURRENT_DIRECTORY) . 解决该问题的方法是,转到“插件”菜单,单击“ NppExec”,然后选择“ Follow $(CURRENT_DIRECTORY) After that I can run programs just fine. 之后,我可以运行程序了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM