0

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.

Note: I'm using 1.8.0_20 rather than 1.7.0 as described in the answer.

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:

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?

1
  • If you use 1.7.0 you will have to add JavaFX to the classpath manually. Commented Oct 5, 2014 at 21:31

2 Answers 2

1

I had this problem in Notepad++ too. What I did to fix it was I went to the Plugins menu, clicked on NppExec, and selected Follow $(CURRENT_DIRECTORY). After that I can run programs just fine.

Sign up to request clarification or add additional context in comments.

Comments

0

The very first line of HelloWorld.java reads:

package helloworld;

Java packages are mapped to directories on the filesystem, so the interpreter expects to find HelloWorld.class inside a helloworld directory. Move the .class file to a helloworld subdir and run it as:

> java helloworld.HelloWorld

from the parent directory (i.e. the directory which contains helloworld/).

3 Comments

Maybe, I'm doing it wrong, but I've created the "helloworld" subdir and moved the .class file into it, but I get the same error.
Probably that's a problem with how Notepad++ executes the .class file. Try removing the package helloworld line and see if it works.
Just tried this, seems to compile normally, but compile and run command starts then doesn't do anything (starts but doesn't finish or throw error). Also tried with another version of Hello World (found here:docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html). Got the same error. For reference, the file is saved as HelloWorld.java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.