.class file stopped getting generated suddenly in Eclipse IDE - java

I am working on an automation project where I automate manual processes of general insurance sector using JAVA and SELENIUM WEBDRIVER. I have created a java project in eclipse. Inside it under src I created a single package containing 6 .java files.
I wrote 90% of the code and tested all the files. They were running properly and showing the automated output. One day I appended some lines of code to a java file. It was called from main method class where main method class suddenly started showing error under the name of that class. Firstly it said to import the class which itself was in the same package of main class. Secondly even after clicking on importing command of the class the error did not went away.
Lastly I cleaned the project in eclipse and the error went away but when I tried to run the project then it gave the error as NoClassDefFoundError and ClassNotFoundException. I checked the bin folder inside the project folder on drive. There .class file for the error class was missing while other classes .class file was present. Everytime I make changes in the main method class and save it eclipse starts showing error under that class name. The error goes when I clean the project. It is a repetitive occurrence in eclipse.
Code for all java classes without main method are 99% same still error is coming for one java class only while other java classes are running fine with almost the same lines of code
Can anyone please explain me the reason behind such behaviour of java compiler in eclipse. Its really a strange show of java compiler the reason behind which I am not able to understand. Please do let me know about the reason behind this act of JAVA compiler in eclipse as I am very curious to know the reason for it. I use jdk 1.8 and selenium standalone server ver 3.0.1
Thanks in advance for your answer.

Related

Could not find or load main class in vs code

The case:
I have created a complex java project (spring boot) with maven build in IntelliJ and I was able to run it, everything was working fine. Now, as IntelliJ hasn't a community edition with spring boot, I had to move to vs code. I didn't change anything in my project, I just opened the folder (which contains the pom.xml and the src folder) in vs code and let vs code load the java project (earlier I installed all the extensions like spring boot, java, etc. for vs code).
After vs code opened the project successfully, I wanted to run it in the main method by clicking the run text (I inserted the image, that you can see the folder structure):
But as stated above, I get the famous error. I reloaded the window, I cleared the workspace, I set the JAVA_HOME and CLASSPATH variables in the env variables and tried, tried, tried it again, but no success. What the hell can I do on top of that? It worked in IntelliJ, it should work in vs code too. I use java se17. Note, that if I start a new simple project, the program get's compiled and executed without any error.
Another curiosity is, if I try to load the maven dependencies, vs code says, that it can't create the dependency tree, but if I run the mvn dependency:tree command, I get all the dependencies and it says, that the build was successful.
What is going on here?
EDIT: my antivirus program blocked maven, so, the problem with the dependency tree is now gone, but the error with the classpath remains.

Java & Eclipse :: Eclipse Doesn't Recognize Common Packages in an Imported Project

I have what is probably a stupid question... but here goes anyway. Some years back, I wrote a "Star Trek" game in Java 8, using JavaFX and Eclipse IDE. The project grew to be fairly large, but it worked. When I finished, I made sure to export the project using Eclipse's File --> Export menu.
I recently grew nostalgic and decided to import the "Trek" project into Eclipse on my current laptop. (The original laptop died.) FYI, my current version of Eclipse is Version: 2018-12 (4.10.0), which I thought was pretty recent.
The project imported just fine, but Eclipse seems mystified by everything in it. For example, when I try to compile and run the project, this error comes up immediately:
Error: Could not find or load main class gameEngine.MainEventTrek
Caused by: java.lang.ClassNotFoundException: gameEngine.MainEventTrek
gameEngine.MainEventTrek contains the project's main() method. Eclipse can't find it??? But the java file is right there, right in the project's src directory:
That's not all. When I open the Java files, Eclipse seems ignorant of how to import common packages:
Look at that; Even line 1 has an error! ("The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files") I can understand that Eclipse might not know about JavaFX - I can't remember if I installed it - but Eclipse doesn't seem to know about common packages like java.math and java.util. Heck, later in my code, Eclipse doesn't know what the System package is, so all my System.out.println() commands are now throwing errors.
I'm a fairly good Java coder, but I'm pretty stupid when it comes to resolving basic compiler issues like this. Does anyone have any idea what the issue might be and how I go about fixing this? Thanks... and Live Long and Prosper.

Problem running a test with src/main and src/test

Newbie to Java having issue with an existing code base.
It seems Java files in /src/code are not being picked up.
Other devs here use IntelliJ, which runs tests fine out of the box (default config). I'm trying to use VSCode but also get the same result running via the terminal:
Running a test gives me a "cannot find symbol" error trying to import local classes from /src/test/... If I copy the problematic file into /src/main/... that file imports fine but error reappears with the next imported file, and so on.
Note that command clicking the 'missing' file opens its source in VSCode, so I know it's there.
import is standard:
import com.foo.bar.baz.math.TestMathModelFactory;
File exists under:
work/src/test/java/com/foo/bar/baz/math/TestMathModelFactory.java
It builds if I put it under:
work/src/main/java/com/foo/bar/baz/math/TestMathModelFactory.java
Expect it to import, but get:
RTPTest.java:3: error: cannot find symbol
import com.foo.bar.baz.math.TestMathModelFactory;
^
I know I'm doing something stupid, but ¯\_(ツ)_/¯
LOL, was my own Pebkac issue. I was trying to run the tests via the VScode "Code Runner" extension – which, in retrospect, has no idea how the project is set up. When I ran the tests via the "Java Test Runner" extension, they ran fine.
I told you the issue was my stupidity! Thanks for the ideas anyways!

Java and Scala ClassNotFoundException after upgrading to IntelliJ 14

I recently upgraded to IntelliJ 14, then added Scala support.
My main files stopped running. For example the GUI file, which has no errors and is a totally self contained hello world style for testing this error:
Exception in thread "main" java.lang.ClassNotFoundException: GUI
It makes no sense and I'm pretty frustrated that the IntelliJ devs are slacking in not auto-detecting a solution to this. I have tried everything to fix it. From settings, compilers, to making the project from scratch.
I only had a bit of luck when making it from scratch, but as soon as I started to add my other files (files that were not even being used!) it starts with the error.
It seems that any files outside of the original project module (when creating a new project to test fix) will not run giving ClassNotFoundException.
This may be related to my other question: https://stackoverflow.com/questions/27516673/cannot-run-file-located-out-of-main-module-intellij-14-java-scala
Sample View of the problem
I had the same problem and was able to fix it by right clicking the directory my class was in, and clicking Mark as sources root. This should make your class discoverable and able to run.
Solution
Turns out that Make, No Error Check does not work the same for scala as it does for Java.
Errors in the scala files will cause an ambiguous error message on run, with no clear link to the error.
Fixing the scala files fixes the error.
In my case, the solution was at the JDK and java level.
When I set JDK 14 this error occurred.
So when I work with a scala project, I set java 8 everywhere in the project(module) settings and in the configuration of the main method.
In project(module) settings section: Project, Modules, SDK's
In main method settings: JRE

Eclipse and class files

I've got some class files that open in Netbeans (with .java extension) but in Eclipse I had the following experience:
At first I could not see the content of the class files with jadclipse and I only saw:
/jadclipse/
//Error!
A few days later (without any change to eclipse or ...) I could see them but with errors like the ones bellow:
"Couldn't fully decompile method ...
Couldn't resolve all exception handlers in method ...
Overlapped try statements detected. Not all exception handlers will be resolved in the method ..."
But the other day I ran into the first error that I could not see anything again!!!
OS: Win7
Java: 7
Netbeans 7.1.2
Eclipse version Juno Service Release 1
Any suggestion?
I didn't get any help on Eclipse plugin of JAD as I said it didn't work for my class files. So I tried Java Decompiler GUI and it worked very nice, therefore I wanted to share this nice experience so that it might be useful for some body.

Categories

Resources