Java not compiling changes in my code - java

I have this problem with both Netbeans 8.0 and Eclipse. In Eclipse when I can write a Java program and it will compile and run fine. Then I can make a change to the source and when I run it again sometimes the old version of the code without the change in the one that is run. If I hit run a second time the new version is run.
In NetBeans I get a different error the second time I try to run updated code. "Could not find or load main class". This happens sometimes when I make changes to the source. I think this might have a similar cause to what is going on in Eclipse. In both cases the problems are intermittent and difficult to reliably reproduce.
I am using JDK 7 but before I was using JDK 8 and had the same problem.

I don't know about netbeans but in eclipse if you change code and you don't save before launching sometimes it executes the old code. So ctrl+s or hit the button save before launching every time. It seems that the run and save command are not issued by eclipse in the same order so it runs and saves at the same time but runs the old code.

i don't have the rights to comment right now so here it goes, i faced the similar problem when i was using net-beans 8.0. the main reason behind this problem is your classpath.("could not find or load main class").one way to ignore this problem is to set the classpath as the current directory(which can be done by using " set classpath=*;".). kindly revert if this doesn't solve your problem.
p.s: try it to compile with dos.
"C:\Program Files\Java\jdk1.8.0_05\bin" and you are good to compile.
and in eclipse, when the present src code has some errors.. it tend to compile and run the previous code.

Related

Eclipse projects stopped working out of nowhere

I was just looking at my java project in eclipse, compiled it, and after closing program all projects in my solution show billions of errors.
Example:
The import java.awt cannot be resolved
When i try to compile it show error:
A JNI error has occured, please check your installation and try again.
Any clues how to fix it? I had many problems with java in the past and i couldn't fin any fixes, almost like it was designed to fail. This language vexes me, but sometimes you just have to use it.
Edit
I also get this error while attempting to open it in IntelliJ (just downloaded it):
JDK jre.1.8.0_241 is missing
Edit
Its just Java being Java (aka not working, as usual). You have to create new project and just copy everything to it, it will work.

How to work with NetBeans IDE 8.2 on Windows 7 64-bit with JDK

I've been having trouble using NetBeans IDE 8.2 with JDK on Windows 7 64-bit. NetBeans can compile code, but doesn't run it. I've downloaded all of the necessary files and programs and even consulted with a computer programming teacher, but I haven't been able to work around this issue. The URL displays an image that shows what I get back after attempting to run a code.
https://i.stack.imgur.com/RsEvx.png
I appreciate any help I can get.
Thanks,
--Sam
JavaApplication1.java is still set as your main class.
To change your main class, go into Project Properties -> Run and change "Main Class" to TestClass.java.
Essentially, the compiler is still running whatever main function is found in JavaApplication1.java.
#notyou Also mentioned how you can right click a file and run it directly, instead of changing the project settings. I used to use this but it slipped me! This is super useful.
I'm pretty sure this question has some answers for you.

IntelliJ - How to run current program regardless of errors in unrelative files

I am start learning Scala, I am using
Java 7 and
IntelliJ IDEA 2016.1.4
Build #IC-145.2070, built on August 2, 2016
JRE: 1.8.0_77-b03 x86 JVM: Java HotSpot(TM) Server VM by Oracle Corporation
I got some sample code programs online and trying to run one by one.
But not working, while I try to run, it showing errors in other files but there is no relationship with them, all most all are independent Scala classes only.
IntelliJ Idea, run code regardless of errors in unrelated project files
I followed this similar issue, but I am not able to find options they suggested. like "Make before launch" and other might be very old post.
The option is still there, you just need to look for it in your run configuration window.
As you can see in the below GIF, when you create a run configuration it will implicitly run make before running, and initially it will fail.
The, you edit the run configuration and replace make with make, no error check. If you get a ClassNotFoundException when launching it right after, just re-run it again. I haven't figured out why this happens, it's probably related to how IJ cleans and compiles the classes in this particular case.

DrJava: Cannot run code using JDK8.0

Anyone having trouble using jdk 8.0 ??
Well, I don't know why I am facing some disturbances.
Not sure why , after compiling a javacode in 'drjava' while I try to run it , it says ...
" Current document is out of sync with the Interactions Pane and should be recompiled! "
I tried changing the compiler from JDK 8.0 to Eclipse Compiler 0.A48 it showed the same message .. after frequently recompiling and clicking the run button rather than using the shortcut key (F2) it ran !!!! then I toogled the compiler back to JDK 8.0 it ran also .(also the shortcut worked ) ..
But after few compilation of codes it started to show the same text ...
And the most irritating thing is now my drjava hangs while i try to change my compiler !!!
I think I have to go back to JDK 7u51 .. but I am really curious why this thing just happening
I'm getting errors when I try to run it with JDK 8 as well.
My temporary solution: download JRE (or JDK) 7 as a tar.gz, and DrJave as a jar. Unzip the JRE/JDK, and just run the jar with the v7 java
Works for now. I'm sure they'll get it sorted eventually, but meanwhile...
I am running DrJava on JDK 8 and I faced the same issue when I ran DrJava Windows App. I now run DrJava jar file instead of windows app.
This may also happen if you're trying to run your code which has been modified(accidently or otherwise) after your last compilation. Just compile it again (shift + F5) and run (keyboard - F2).
Unlike Eclipse and other sophisticated IDEs, DrJava requires you to compile all modified code before you run it.
Firstly, try to change the compiler from compiler output option given as shown. I hope it works. If it doesn't, download the jar file of dr java and do the necessary changes.

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file "name of class"

I know this question may seems stupid since i cannot give a lot of infos about it, but I think that the problem has to be some kind of bug...
I have written a java program whith NetBeans 7.1, which now gets me this error when trying to run. 10 mins ago it was perfectly running, and i have changed nothing to the class the error refers to
Could this be some kind of NetBeans error? Maybe it is a well know problem?
It also got this exception in NB 7.2
'clean an build' and restarting NB didn't work
updating NB with the latest updates and performing 'clean and build' also didn't work.
So i renamed the cache directory:
c:\Users\userabcd\AppData\Local\NetBeans\Cache\7.2\index\
started NB, waited for it to finish 'background scanning' and pressed 'Debug project' and voila. The cache gets corrupted every once in a while :-/
EDIT: Added Solution B below.
Solution A:
Project Properties
Build >> Compiling
un-check: Compile on Save
Clean and Build
Notes A:
If you leave Compile on Save un-checked, you won't have this problem any longer for this project.
If you enjoy the benefits of the Compile on Save feature, you can re-check the option after you clean and build, and continue work on your project as normal.
Compile on Save is meant to save time by constantly recompiling your .java files into .class files in the background as you save changes to your source code. That way when you build or run your project, most of the compiling work has already been completed allowing you to run and test your code quickly, even for large projects.
NetBeans uses some fancy caching and versioning to avoid having to recompile your entire project every time you save a file. That's why the other solutions listed here will often work; they are ways of defeating this caching-and-versioning system when it occasionally fails, as it has above.
Solution B:
Create empty folder e. g. C:\Temp\mine
Create a new shortcut for NetBeans
with command line parameter in Target:
"C:\Program Files\NetBeans 8.2\bin\netbeans64.exe" --userdir "C:\Temp\mine"
When compile errors occur
(ClassNotFoundException, MethodNotFoundException, etc...)
delete C:\Temp\mine\var\cache
Notes B:
You'll lose all your NetBeans settings the first time.
Much easier to solve future compile errors caused by caching bugs.
Allows running multiple copies of NetBeans, one per userdir.
I got also this exception. My solution was:
edit and save mentioned class (.java file)
clean & build project
deploy to tomcat server
I just had this happen to me with Netbeans 7.4 Beta.
Things I tried:
Restarting Netbeans.
Clean and build.
Shutting down netbeans, renaming the cache dir, starting netbeans and waiting for scanning to complete.
What worked for me:
Making the source file writable and saving a meaningless change (inserting a space).
I don't know why any of the other steps didn't fix the error. Maybe it would have worked if I had done a clean and build after renaming the cache dir?
Its a very frustrating situation to be in - Hopefully this helps someone (perhaps a future me?).
The JDK says for ClassFormatError:
Thrown when the Java Virtual Machine attempts to read a class file and
determines that the file is malformed or otherwise cannot be
interpreted as a class file.
Perhaps a class file has become corrupted. I am going to do the standard IT support statement.
Have you tried restarting NetBeans?
Hope that helps
Got right the same thing with Netbeans 7.1.
Working on a project that works fine for several months.
Now I changed a bean which gets persisted with javax.persistence and now this exception got thrown. Reverted my few changes, clean and compile the project, reboot the whole system: still exceptions.
The curious thing about it: the generated .war works perfectly in a Tomcat at another machine.
UPDATE:
Today I got the same problem again and I couldn't recall how to solve it, but I found this post again. ;)
After a half hour I found the solution: Just change value of the property serialVersionUID, redeploy the app and then you can change the value to its original value and redeploy again -> working.
Seems like Tomcat is holding that class somewhere deep inside – deleting working directories didn't led to success.

Categories