I'm new to Eclipse and am trying to write a Hello World! program.
Wondering how to fix this error:
Here is my code:
public class HelloWorld {
public static void main(String []args) {
System.out.println("Hello World!");
}
}
And the error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: (my workspace)/helloWorldHomeworkI/bin
Caused by: java.lang.module.InvalidModuleDescriptorException: HelloWorld.class found in top-level directory (unnamed package not allowed in module)
Do I need to create a package or is there a package that's made when I create the new Java Project that I just need to put in my code?
I tried just typing in "package projectname;" (no quotes in the code) but I don't know how to find the right name of the package. Or if I can make a package or even need to have one.
Related
I don't know if this question has been asked/answered yet. If so, I'm sorry. But I'm new to IntelliJ and there's a lot of foreign words I yet need to understand.
My problem is as follows:
I installed the complete IntelliJ package, created a new Java project and created a new class inside my src folder:
package de.itsme.hello;
public class Hello {
public static void main(String[] args) {
System.out.println("Hello");
}
}
So I try to run it and I get this Error:
Error: Could not find or load main class cucumber.api.cli.Main
Caused by: java.lang.ClassNotFoundException: cucumber.api.cli.Main
I tried adding cucumber-core:4.0.1 to the project's dependencies but then I got another exception:
Exception in thread "main" cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
at cucumber.runtime.BackendModuleBackendSupplier.get(BackendModuleBackendSupplier.java:39)
at cucumber.runner.SingletonRunnerSupplier.createRunner(SingletonRunnerSupplier.java:38)
at cucumber.runner.SingletonRunnerSupplier.get(SingletonRunnerSupplier.java:32)
at cucumber.runtime.Runtime.run(Runtime.java:75)
at cucumber.api.cli.Main.run(Main.java:26)
at cucumber.api.cli.Main.main(Main.java:8)
I don't need cucumber or at least not for now. Is there a way to make it either work or remove it from the project?
Thanks in advance!
Maybe you have the packet JDK installed incorrectly and this produces you an error. Or maybe your classspath is incorrect.
I have started learning Java and encountered a problem when trying to run my first program as given below:
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello world!");
}
}
On Eclipse Photon I encounter this error when running it:
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\Thomas\eclipse-workspace\HelloWorld\bin
Caused by: java.lang.module.InvalidModuleDescriptorException: HelloWorld.class found in top-level directory (unnamed package not allowed in module)
I looked and there is my .class file in bin directory and my .java in the src directory.
Is that normal? How do I fix that?
I was getting the same error. Deleting the module-info.java file solved it for me.
It seems that you haven't created a package. My usual procedure in Eclipse is:
Create a new Java project
Inside that project: Create a new package
Inside that package: Create a new Java class
Eclipse will help you a lot with the settings. Then just copy your code into that class and hit the 'start' button.
by removing module class problem solved for me in eclipse
i moved my main class and sample.fxml file to a new package that throws this error below
"Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\Thomas\eclipse-workspace\HelloWorld\bin
Caused by: java.lang.module.InvalidModuleDescriptorException: HelloWorld.class found in top-level directory (unnamed package not allowed in module)"
i moved my class file and fxml file to normal position. it fix my problem. but i have to find why it happends. cheers....
Executing the project from another workspace solved for me in Eclipse.
create a package and refactor your Main class in that package in your case its HelloWorld then it will run fine.
To understand how modules work in java please watch this spectacular video MODULES IN JAVA
I've solved it do according to this steps:
right click on your main project name
choose new>>package
in the opening window fill name field and then choose (radio button) "create pakage info"
then click ok and in package explorer drag your class under the new package which you created, then run it.
Delete module-info.java from your project and run ,it should work. Or Create package and then create class inside package.
Have a simple programm:
package com.test;
public class Main {
public static void main(String[] args) {
System.out.println("lol");
}
}
In Intellij Idea project run correctly, but if i run out class file by cmd, like java Main.class i have a Error
Error: Could not find or load main class Main.class
If i compile .java manually - i have some error.
In $PATH path to .../jdk/bin. In Intellij Idea path to SDK .../jdk.
What's the problem?
Thanks!
Your class is not Main, but com.test.Main. You should use:
java com.test.Main
from the root directory of the compile output (i.e., from the same place as the com/ folder)
In Eclipse, I wrote a Java class Test with a main() function.
The project in which is defined the class, I added the jar file bcprov-jdk15on-151.jar (I am using the library BouncyCastle).
In Eclipse, there is no problem and my program runs normally. But when I try to do it in a terminal, I get an exception.
After checking SO I found a similar post: NoClassDefFoundError while running a java program in terminal from IDE but the solution given doesn't work.
To illustrate my case, in the directory C:\Docs\workspace\Terminal\bin\ I have the file Test.class. If I run java Test I get Exception in thread "main" java.lang.NoClassDefFoundError: org.bouncycastle.math.ec.ECFieldElement.
If I run java -cp bcprov-jdk15on-151.jar Test (I put the .jar in the same directory to simplify) I get Error: Could not find or load main class Test so it seems that the dependency error is solved but another one occurs.
What am I doing wrong? Just to give the structure of my .java file:
import java.io.*;
...
public class Test {
... local methods ...
public static void main(String[] args) {
...
}
}
Thanks in advance.
Try this, you forgot to include current path "."
java -cp ".;bcprov-jdk15on-151.jar" Test
Hope it help
I'm using Eclipse on a Mac. I'm learning java - previously used python.
Originally created a new package and it worked fine, using public static void main(String[] args)
In a separate package, I added acm.jar to my build path. That works fine: import acm.program.* and I use public void run()
Now my original package foo gives me an error:
Exception in thread "main" acm.util.ErrorException: Cannot determine the main class.
at acm.program.Program.main(Program.java:1358)
acm.jar isn't in my build path for foo. Do I have to remove acm.jar from all my packages?