IntelliJ cucumber .ClassNotFoundException - java

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.

Related

InvalidModuleDescriptorException when running my first java app

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.

Error: Could not find or load main class Neon Eclipse

I'm trying to execute carel programs based on CSA106a Stanford class videos available on YouTube.
I've downloaded the jar and related files, imported the whole project into Neon Eclipse and am trying to run.
While clicking "run", I get the error:
Error: Could not find or load main class (default package).CheckerboardKarel
Note: other programs that I have created in Neon from scratch are working fine (not imported ones). Please help.
I've attached the screenshots as well.
I can't tell for sure, but I think there might not be a "main" function in what you downloaded. In order for a java program to run the class you are running needs to have a main function. it should look like:
public static void main(String[] args){
...
}

Java Error in SizeOf library

I saw this link which uses Instrumentation to calculate the size of objects during runtime. I decided to try this library since It can be really helpful in determining the size of big data structures.
So I wrote the following code in a new project named TrySizeOf using NetBeans IDE:
package trysizeof;
import net.sourceforge.sizeof.SizeOf;
public class TrySizeOf {
public static void main(String[] args) {
String s = "abc";
System.out.println(SizeOf.deepSizeOf(s));
}
}
After that I created a folder named lib inside my project, and placed SizeOf.jar in it. Then under Project->Properties->Run I placed the following parameter:
-javaagent:/home/MyUserName/NetBeansProjects/TrySizeOf/lib/SizeOf.jar
However, when I attempt to run my project I get the following error:
Error occurred during initialization of VM
Error opening zip file or JAR manifest missing : /home/MyUserName/NetBeansProjects/TrySizeOf/lib/SizeOf.jar
agent library failed to init: instrument
Can any one help me with this? or maybe explain what did I do wrong?
UPDATE:
I found the error, it was a problem with the upper and lower cases. When I started the project for the first time I made a little upper and lower case typo. When I paid attention to it I fixed it, but I kept getting the same error (However the path was fixed). Now, I tried using clean and build and the project worked. It was that when I do a clean and build manifest file gets updated which is used to specify the path of premain method. When I tried clean and build the file got updated and the project finally worked. Thanks for the comment about a typo in my post, which somehow made me think about this.

java.lang.NoClassDefFoundError with jar file in terminal

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

Java: Eclipse: Cannot Find Main Class

I had a project that was compiling and running fine. I had also exported the build.xml file without issue. However, today, I clicked Project --> Clean..., and the project will no longer run. It raises the error:
Error: Could not find or load main class com.bar.Foo
Is there any way I can undo this?
The answer is probably no, you cannot "undo" this. You can probably fix it by building your project, making sure that the project/class exists and that it contains a public static void main(String ... args) method.
Perhaps the file that you're trying to run was removed from the src folder.

Categories