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.
Related
I am working with TestContainers for my project but when I am running the test in eclipse, I am having the following error with me
On top of this window, it also gives a specific error which says Cannot find test class "DBInitTest" in project "myProject".
package org.ft.cdcp;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.junit.jupiter.Testcontainers;
#Testcontainers
public class DBInitTest {
private final PostgreSQLContainer sqlContainer = new PostgreSQLContainer(DockerImageName.parse("postgres:alpine"));
#BeforeEach
public void setUp() {
sqlContainer.start();
}
#Test
#DisplayName("Initializing database container")
public void initTest() {
assertTrue(sqlContainer.isRunning());
}
}
Do note that I have checked and rechecked the dependencies, everything is intact and there's no problem with them, something's buggy only about JUnit5.
I looked it up online but only found something which said that I should Right click on source folder --> Build Path --> Use as source path, but this fix doesn't seem to be working for me.
I am not expert and cannot explain why this fixed any but:-
Today I started having the same problem as you reported.
After fiddling about for a while (reinstalling STS, lombok ...) I eventually clicked on the error entry that popped up. It took me to "Edit lauch configuration properties" for the Test that would not run.
Once there I clicked on the "Search" on the line of the "Test Class:" field.
I selected the correct class from the "Test Selection" window that popped up.
(nb what I thought was the same value that was already there)
UPDATE
Now I feel silly.
I had a test class called "AdminTaskControllerMockMvcTest" in a file called "AdminTaskControllerMockMvcTests.java", ie class name with an "s" on the end.
Renaming my test class to "AdminTaskControllerMockMvcTests" fixed all my issue.
Regards, Andrew
So I figured out what the error was.
My project structure was like this:
└─main_project/
├─ myProject/
└─ other_sub_project/
It might sound stupid but it's definitely something beginners tend to often (as I did). I have opened the main_project in my IDE and there were other sub-projects inside that projects too. The DBInitTest was inside the sub-project named myProject.
I was getting the error because of this structure only. So when I closed the project and opened the sub-project directly from the IDE, the error was gone.
Steps to resolve:
Close the currently opened project i.e. main_project
Click on Open Project in your IDE
Navigate to the folder of the sub-project i.e. myProject and open it inside your IDE
Voila, the error is gone now. ;)
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'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){
...
}
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.
I am facing a problem while i am trying to compile a code at eclipse in java. The code is the following:
public class New {
public static void main(String[] args){
System.out.println("hello world");
}
}
Parts that have errors are New, String and System. I have checked at error list and the description for error's is like:
Unable to create editor ID
The file does not exist
Any idea why this is happening?
Your project has or classes maybe has beeing dissapeared.
I can give you a possible solution
Solution: Shut down Eclipse IDE Start Eclipse IDE (with -clean to be super-safe) Reimport all projects (UPDATE: Just use File->Import->Existing Project into Workspace and browse your workspace/project directory)