Eclipse java.lang.module.FindException and java.lang.ClassNotFoundException - java

I recently installed Eclipse 2020-06 and am using JDK 10.0.2. I wanted to test Eclipse using a simple Hello world program:
package eclispeTest;
public class eclipseTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello");
}
}
But I get the error: Error occurred during initialization of boot layer java.lang.module.FindException: Module eclispeTest not found
One quick fix I see for this to delete the module-info.java file but when I do this I get the error: Error: Could not find or load main class eclispeTest.eclipseTest Caused by: java.lang.ClassNotFoundException: eclispeTest.eclipseTest
I saw one potential fix that told me to go to "Check your project build-path and enable specific output folders for each folder. Go one by one though each source-folder of your project and set the output folder that maven would use."
from: Eclipse - java.lang.ClassNotFoundException
But I am new to Eclipse and have no idea what they are talking about.
I have also noticed that when I open the problems tab at the bottom of Eclipse there is one problem that is repeated about 8 times: Description Resource Path Location Type The project was not built due to "Failed to init ct.sym for C:\Program Files\Java\jre-10.0.2\lib\jrt-fs.jar". Fix the problem, then try refreshing this project and building it since it may be inconsistent eclispeTest Unknown Java Problem
Could someone help me figure out what I should try, with baby steps for how I should do it.
Thank you in advance.
PS in case it helps here is a picture of my Eclipse window after I try to run my code:
EDIT: I made a new java project and below is my java project cration window
(I still got the same error)

Fist of all, In order to work the line " System.out.println("Hello");"
you will require two classes
1)java.lang.System
2)java.io.PrintStream
using above two classes the code runs.you don't have to import these class,because JRE(Java Runtime Environment) automatically does for you.
If you are gettting this error
Error occurred during initialization of boot layer java.lang.module.FindException: Module eclispeTest not found
Which means You didn't setup your "Java project" properly with "JRE"
Let create new project to solve this problem
1)Open Eclipse IDE
2)click FILE (top left most)
3)New
4)java project
5)give you project name (make sure that- "use default location checkbox" clicked)
6)IN JRE section - select use an execution environment JRE(edition as required)
7)Then click finish
This would have solved your problem , go create a Class do your eclipseTest. This time it should work.
java project creation should look like this

Related

Java - Eclipe IDE error - Error occurred during initialization of boot layer

I am using Eclipse for the first time, I just finished installing it, I typed the code below as instructed by my online course:
System.out.println("Hello World");
and I got the error below :
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\seljouki\eclipse-workspace\MyFirstProject\bin
Caused by: java.lang.module.InvalidModuleDescriptorException: MyClass.class found in top-level directory (unnamed package not allowed in module)
Seems a "modul-info.java" related" topic.
Suggestion:
Restart Ecclipse and/or delete projects
Create a new project and when creating a new project do NOT select "module-info.java"
Create a package e.g. hellloworld (package.de.helloworld.chapter01)
In this package right click and create a java class (here HelloWorld)
Run this project as Java application
this should work.
You need also the main statement, you included this? :-)
package de.helloworld.chapter01;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
I had the same problem. I had class in default package. I deleted the class and moved it in to a new package. That fixed problem for me.
The following steps solved it for me;
Right-click on your project and select 'Properties' at the bottom.
Select 'Java Build Path' and navigate to the 'Libraries' tab. Remove
existing libraries.
Add a new library by clicking on 'Add Library' from the menu on the right.
Select 'JRE System Library' and click 'Next'.
Under 'System Library' select 'Execution Environment' and click
'Finish'. Apply all changes & close.
Run your program now.

'Could not find or load main class' in Eclipse. Again and again

I'm asking this question even though it has already been asked many times because I didn't find a solution after hours of searching.
I'm using Eclipse to learn Java. Last week everything worked properly. I could run whatever I wrote. Then today, I opened Eclipse, wrote some lines and when I tried to run it, I got an error:
Error: Could not find or load main class test.ArrayTest
Caused by: java.lang.ClassNotFoundException: test.ArrayTest
But that's not all : every project in my workspace is having the same issue. I can't run anything. At first I thought it was because I made a mistake at Eclipse start, so I closed it and re-opened it, but I was in the correct workspace.
I've tried to clean/rebuild it, doesn't work.
I've tried to mess with Properties > Java Build Path, doesn't work.
I've tried to create a new project with a simple 'Hello World', doesn't work.
package Hello;
public class Main
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}
What I have in package explorer.
Console display.
The thing that suprises me the most is that I don't think I've done anything that can mess with Eclipse between the moment it was working and now.
Does someone have another idea ?
I think I found the root of the problem !
The path to my workspace was containing a letter with an accent ('Bibliothèque' by default with Windows 7+ in french...), so I tried to create a new workspace outside of it, and it worked !
I'm not a 100% sure it was really it, but since it worked, it's worth sharing.
Probably you have disconected JDK in project.
Try open conextual menu on project (right mouse button)
properties/Java Build Path/Libraries
check is correct JDK or remove
then: [Add Library] / JRE System Library/ Alternate JRE/ [Installed JREs] / [Add] / Standard VM / [directory]
select path to your JDK (not JRE) and confirm, select checkbox your new jdk and [Apply and close]
on select list choose your new jdk and [Finish] and [Apply and Close]
should works. I have sometimes this problems. It's Eclipse

Adding spock to eclipse without maven: General error during semantic analysis

I am trying to do my first test-automation with Spock.
I do not want to use maven.
I am using eclipse java EE oxygen 4.7.
I have created a groovy project.
I have added the Spock jar as an external library in the build path configuration.
Spock ist Spock-core-1.1-groovy-2.4.
I have also added geb jar the same way.
However, I am getting this strange error from the automatic build, which I do not understand and I am seeking for help. So far I haven't found anything helpfull.
General error during semantic analysis: Transform org.spockframework.compiler.SpockTransform#xxxx cannot be run org.codehaus.groovy.GroovyException:
Transform org.spockframework.compiler.SpockTransform#xxxx cannot be run at
org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:416) at
org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:972) at
org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:633) at
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:609) at
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:586) at
org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.processToPhase(GroovyCompilationUnitDeclaration.java:217) at
org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.resolve(GroovyCompilationUnitDeclaration.java:613) at
org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:879) at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:141) at
java.lang.Thread.run(Unknown Source) Caused by: java.lang.NoClassDefFoundError: Unable to load class org.spockframework.runtime.ErrorCollector due to
missing dependency org/junit/runners/model/MultipleFailureException at org.codehaus.groovy.vmplugin.v5.Java5.configureClassNode(Java5.java:397) at
org.codehaus.groovy.ast.ClassNode.lazyClassInit(ClassNode.java:353) at org.codehaus.groovy.ast.ClassNode.getDeclaredMethods(ClassNode.java:981) at
org.codehaus.groovy.ast.ImmutableClassNode.getDeclaredMethods(ImmutableClassNode.java:105) at
org.spockframework.compiler.AstNodeCache.(AstNodeCache.java:65) at org.spockframework.compiler.SpockTransform$Impl.(SpockTransform.java:
52) at org.spockframework.compiler.SpockTransform.visit(SpockTransform.java:47) at
org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:395) ... 9 more
My code is as simple as you can get. This is the code:
//The error is on the "p" letter of package
package hellowworld
class HelloWorld{
static main(args) {
}
}
Please note that this error only happens when I add Spock jar. The closest question was Spock without maven or gradle, but obviously the problems are different.
I just cut the file from the package directory pasted it out side and then recut pasted in the package back. It worked well and I have no idea why.
This is one of those problems which occasionally arise in Eclipse and most people just won't know why!
The thing to do usually is to try several "strategies" and hope that one will work. If not you have to come back to SO and try to enlist the support of an expert.
One tip: in my experience sometimes it is worth trying "Refresh Gradle" and "Build all" more than once. Not only that, but sometimes trying either of these actually then seems to do nothing... but a couple of seconds later the horrid x in the red box then vanishes like morning mist!
Highlight/select the project in Project Explorer --> right-click --> Gradle --> Refresh Gradle Project
Put cursor in a code file open in the editor, press Ctrl-B (Project --> Build all)
Close all files in editor, close Eclipse and start up Eclipse again
Try the above in various combinations
Reboot and then try the above in various combinations
If this fails to cure it you may need to turn to SO.

Testing Java code with Groovy under Intellij: unable to resolve class GroovyTestCase

I need to write a short test for some Java code. I used CTRL+SHIFT+T to generate one with IntelliJ, and selected "Groovy JUnit" as the testing library, then wrote the following test:
package util
class FibonacciHeapTest extends GroovyTestCase {
FibonacciHeap<Integer> heap
void setUp() {
super.setUp()
heap = new FibonacciHeap<>()
}
void testAddInOrder() {
testForItems 1..1000
}
private void testForItems(Range<Integer> items) {
items.each {heap << it}
assertEquals heap.size, items.to
items.each {assertEquals heap.remove(), it}
}
}
However, when I right click on the test case in the project window, I don't get the "Run All Tests" option that I normally do with JUnit tests, and the compiler throws the following error:
Information:2/4/15 8:15 PM - Compilation completed with 2 errors and 0 warnings in 2 sec
/home/patrick/IdeaProjects/hackerrank/src/test/java/util/FibonacciHeapTest.groovy
Error:(3, 1) Groovyc: unable to resolve class util.FibonacciHeap
Error:(9, 1) Groovyc: unable to resolve class GroovyTestCase
Trying to import GroovyTestCase or FibonacciHeap manually causes the same error. IntelliJ does not add any import statements when I let autocomplete finish the names for me, like it usually would with Java code.
What am I doing wrong?
This worked for me :
Open Gradle window (on right side in my case)
Click on refresh button
Done
I had a similar problem with creating test classes in IntelliJ, and it was solved when creating a new directory outside of the com.company folder (where I had the class I wanted to test).
Create a new directory for the test classes on the same level as your src folder
Right click on your new test directory, and "Mark directory as" --> "Test Resources Root"
Now create a test class, which should automatically be added to your test directory.
Build -> Rebuild project in the IDE itself (as opposed to maven, in my case) did it for me.
In my case, what I did to resolve the issue was rather simple.
Close IntelliJ
Open the attached homepage...
Remove your project by clicking on the x then...
Click on Import Project, Navigate to the build.graddle file of your project and open.
That was it and all the Red highlightings disappeared.
maybe you need add groovy-all rather then groovy,such as :
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
You have to configure Groovy SDK first. See the screenshot
More detailed description in the official document: Configuring Global, Project and Module SDKs
As #sman591 pointed out in a comment, if you are getting the error:
groovyc: unable to resolve class groovy.util.GroovyTestCase
and you already have groovy as a dependency then you are probably just missing the junit dependency.
In IntelliJ IDEA I re-imported the project. It worked then.
I closed idea. I removed .idea folder in the project. And I imported the project.
Then I needed to set up Groovy, see previous answers, mark test directory as test source in all modules of my project.
I was selecting the root folder which had build.gradle file in it, but it didn't work.
Steps followed are similar to #Pila
close the project from intellij
remove .idea, log, out folders
go to intellij dashboard
import project from existing resources
select build.gradle file <-- this is important
now you should see all the tasks are getting build in the background, and once build is finished all red lines are gone.

JUnit4 + Eclipse "An internal error occurred during Launching"

I'm trying to run JUnit4 test cases on Eclipse 3.4.2 but it's not even starting for me. I have the junit-4.7.jar in my build path and the test application.
Here is a simple example that illustrates my problem
package test;
import org.junit.Before;
import org.junit.Test;
public class UTest {
#Test
public void test() {
}
#Before
public void setUp() throws Exception {
}
}
This compiles fine
Then I do "Run JUnit Test case" from Eclipse and I get an error dialog with this message
"Launching UTest' has encountered a problem
An internal error occurred during: "Launching UTest".
java.lang.NullPointerException
What causes these NullPointerExceptions? What am I doing wrong?
What worked for me after trying everything:
Go to help
Install New Software
Work with: Juno
Programming languages (expand it)
Install Java Development Tools
Restart
It works :)
I was able to fix this just by deleting the workspace and the Eclipse directory and starting over.
This worked for me:
create another copy of the test class (CopyOfUTest.java)
run the copy to make sure it passes
go into Run > Run Configurations
under JUnit, find the run configurations for the original class and the copied class
right click and delete the configuration of the original class
rename the configuration of the copied class to the original configuration name
delete the copied class from the project
None of the given answers here worked for me, so I ended up just installing and using InfiniTest instead. It doesn't have this problem, and it also runs the tests automatically so I can focus on my work.
Have you looked in the Eclipse error log? You can see it by opening the "Error Log" view.
http://help.eclipse.org/help32/topic/org.eclipse.pde.doc.user/guide/tools/views/error_log.htm
This error In eclipse can be caused if you are also using the Android Development Kit plugins:
"Launching UTest' has encountered a problem
An internal error occurred during: "Launching UTest".
java.lang.NullPointerException
Can be caused if you are loading a normal Java project into an Eclipse instance with android ADT plugins installed and enabled. In this situation, Eclipse looks for "Android" project files, and doesn't find any. So it says: "NullPointerException".
So to fix it, re-download Eclipse without the ADT Plugin: https://www.eclipse.org/downloads/
Then re-import your project fresh. And the junit tests run without a problem.
Many people hate eclipse for it's enigmatic error messages. It's like we are back in the 1950's punch card world, where there are no error messages. The program just halts and undefined behavior occurs.
Thanks that solved my problem too.
The problem started when i removed an old simulator, and created a new one.
Fix: Like the OP says remove the workspace, make sure to keep the projects inside it :)
then import them back to eclipse
"Sound like a lot of work" ?
Took me less than half a minute !!!
If you are using Android and its associated plugins, then Android only supports JUnit 3.
I resolved the problem by selecting Test Runner as JUnit 3.
In my class, JUnit 4 is added in the build path->libraries.
Then to run the test file, go to: Run As -> Run Configurations then select the corresponding test.java file and select Test Runner accordingly(whether it is JUnit 3 or 4).
Your code works fine for me.
Eclipse
Version: 3.4.1
Build id: M20080911-1700
I right click on the .java file RunAs JUnit Test. This would indicate the problem is caused by an Eclipse configuration problem, not a code problem.
I encountered a similar problem but I am using Python. This is what I did to solve/avoid it:
Removed my .project file and the project from Eclipse.
Created the project again.
Everything was working.
The problem seemed to be in the .project file where there were some references to CDT Builder and were not there in the new .project file.

Categories

Resources