S
S
SerS2016-01-24 23:09:30
Java
SerS, 2016-01-24 23:09:30

How to get rid of "Could not find or load main class helloworld" Java error?

Maybe someone knows how to solve this problem ..
When writing a program in eclipse, everything compiles and works fine, but when I try to run the program through the command line, the error "Could not find or load main class helloworld"
For example, I wrote "Hello World!"

package ru.sers.helloworld;

public class HelloWorld
{
  
  public static void main(String[] args)
  
  {
    System.out.println("Hello World!");
  }
  
}

Everything works in the environment, but when you try to run the compiled "HelloWorld.class" file, you get an error.
Can someone tell me what it could be related to?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
T
Talik, 2016-01-25
@Talik0507

describe the sequence of actions.
Compilation?
Launch?

S
Sanan Yuzb, 2016-01-24
@Sanan07

At startup, you also need to specify the package here
and maybe here

C
coden55, 2016-01-26
@coden55

Are class names case sensitive? helloworld and HelloWorld different classes

V
Vit, 2019-01-14
@vit1967

encountered a similar error Error: Could not find or load main class sample.Main when experimenting with Intellij Idea c Kotlin+
JavaFX the following inconvenient "crutch": If this error occurs, delete the production subdirectory (with all the contents of the previous build results in ) in the out directory.
After that, it is successfully built, but often only 1 time (then again .. and again delete this directory).
How radically to treat did not find. Who will offer what?

I
id_01, 2020-11-20
@id_01

If you created the main class with the Main method in the package, then you need to go to the directory with the main project in the terminal and type the command == for example (java com.javacourse.se.lesson1.Main)
terminal: PS D:\Java_Projeckt_intellij2020_2_3\out\production\ HelloWorld > java com.javacourse.se.lesson1.Main

S
slinar, 2020-11-26
@slinar

I've been struggling with this issue for 3 days! Rummaged everything. I consider it my duty to share.
I started learning Java from the book by Yakov Fine. The program was compiled from the command line. I didn't go to Eclipse IDE. I climbed into the Patch and CLASSPATCH settings, deleted my folders from the Workspace Directory and returned it again and somehow perverted it.
As a result, according to a 5-year-old video https://youtu.be/mDyXljx8dMI (Java Basics. Lesson 6: The first Java program in Eclipse (Vladimir Vysokomornyi)) replaced the default library in Eclipse - JRE with JDK. And it worked. True, the simplest program thinks for 15 seconds.
In an open project, I press File / Properties /, then I selected Java Build Path on the left side, and the Libraries tab in the central part.
Selected the JRE folder and clicked the Remove button. Selected the inscription Modulepath, only after that the button on the right Add Library became active. I press. I select the JRE System Library, then the Next> button, activate the Alternative JRE label and select jdk-15.0.1 from the drop-down list.
I click Finish and Apply and Close.
Only in order for jdk-15.0.1 to appear in the drop-down list, you first had to include this library, as in the video tutorial. I did not connect, it was written The JRE name is already in use (already in use).
Good luck and patience

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question