I have no idea anymore. Since today 14pm the hot-code replace does not work anymore.
I had jdk8_74x64 installed on win10x64.
I test it using this code in a simple project (without maven and without dependencies):
public class Test{
public static void main(String[] args){
System.out.println("hi"); // breakpoint here, it stops always
System.out.println("ho"); // on suspending i change this to "hoy".
}
}
Start eclipse with new workspace - still not working
Restart computer - still not working
Uninstall all JDK/JRE and remove all javaws.exe, install again - still not working.
Uninstall eclipse, reinstall eclipse - still not working
Installed netbeans, using "apply code changes" - still not working.
Delete jdk with all javaws.exe, delete eclipse, uninstall netbeans, use new user, install jdk 8u31x64 install netbeans - still not working
Installed idea-community-edition15+jetbrains, change ho to hoy and apply class-changes (idea notifies me 1 class reloaded) - still not working.
How to get hot-code-replace working?
Hm,
public class Test{
public static void main(String[] args){
System.out.println("hi"); // breakpoint here, it stops always
System.out.println("ho"); // on suspending i change this to "hoy".
}
}
does not work but
public class Test{
public static void main(String[] args){
foobar();
}
public static void foobar(){
System.out.println("hi"); // breakpoint here, it stops always
System.out.println("ho"); // on suspending i change this to "hoy".
}
}
Works great everywhere.
Related
No matter what I do Lightrun will generate the following error message:
General agent error at jvm_internals.cc:186.
This is my first time using Lightrun.
This is my code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println(new Scanner(System.in).nextInt() + new Scanner(System.in).nextInt());
}
}
The code itself runs perfectly.
I am using IntelliJ IDEA 2022.3.1.
LR doesn’t work on this version. A bit buggy on the ij versions for the past 2 months…
I'm trying to get a "Hello World" like java project to be used in matlab. To start easy, I tried to make a simple netbeans project containing only 1 file with some basic functions to test.
With "HelloWorld.java" being:
public class HelloWorld{
public HelloWorld(){
setVersion(0);
}
public static void main(String[] args){
System.out.println("Hello World!");
}
public void setVersion(int aVersion){
if( aVersion < 0 ){
System.err.println("Improper version specified.");
}
else{
version = aVersion;
}
}
public int getVersion(){
return version;
}
private int version;
}
I built this in netbeans to create a .jar, but when trying to connect to it in matlab via the following code it cannot find HelloWorld when trying to make an object.
javaaddpath('C:\Users\<name>\Documents\Netbeans\HelloWorld\dist\HelloWorld.jar')
javaclasspath
myHelloObject = HelloWorld
It gives the following error
Undefined function or variable 'HelloWorld'.
Error in test (line 6)
myHelloObject = HelloWorld
However, when using "example jars" that I downloaded of the internet and connected them in matlab via the same method this seems to work, so I guess there is something wrong with the .jar generation.
What am I doing wrong? Thanks in advance.
Already found the answer: it had to do with Matlab using java 1.7 while the jar was generated in 1.8. Switching to another virtual machine (or generating the jar in another java version) solves the problems. https://nl.mathworks.com/matlabcentral/answers/130359-how-do-i-change-the-java-virtual-machine-jvm-that-matlab-is-using-on-windows
So I updated to Eclipse Mars (4.5) and for some reason I'm unable to use the hot swap code in the debugger. Normally I could do something like this:
public static void main(String[] args){
while(true){
System.out.println("123");
}
}
Then if I started it in debug mode, changed the text to "321", then save, then it would update without the need for restarting it. It behaves exactly like it was run in "Run" mode instead of "Debug".
What I have tried:
Creating a new workspace, creating a fresh project, using the code above, nothing happens
Have several JDKs installed, have tried with java 6, 7 & 8, changed the workspace and/or the project settings to use the different JDKs, nothing happens (the fact that I have several versions of java installed shouldn't matter as it was just the moment I updated eclipse it stopped working)
Tried uninstalling removing any config files to eclipse (on a mac, so that would be every file/folder with the word "eclipse" in the ~/Library folder, ran a "find" search to detect all the files). Then tried to create a new workspace, now project, the code snipped, ran in debug mode, nothing happens on save.
Have also made sure I have "Auto Build" enabled, even tried to "clean" it, and disable auto build, then save the code, then do a manual build while the debugger was running: nothing happens
I'm starting to get desperate as I have a hard time getting work done without having debug mode available so any help/hints in the right direction would be of much appreciation.
HotSwap doesn't work with static methods. However it works fine with instance methods, so it will work on this code:
public class Main {
public static void main(String[] args) {
new Main().f();
}
public void f() {
while(true){
System.out.println("123");
}
}
}
Ok so I finally found the problem. It seems that you can't edit loops while they are running. Say you have a loop like this:
public static void main(String[] args){
while(true){
System.out.println("123");
}
}
Then you can't edit the "123" string.
You can how ever edit methods which are called inside the loop like this:
public static void main(String[] args){
while(true){
System.out.println(methodA());
}
}
public static String methodA(){
return "123";
}
Now you can edit the string "123" and it will update.
This also applies for infinite "for" loops, so guess the rule of thumb is that the method body has to be "re-called" before updating, and it isn't enough to wait for the next loop call.
I am trying to run this project called "hello user". I am new to Java, so wrote a simple program that takes your name, and displays "Hello ". while Running it, I get the following error:
run:
Error: Could not find or load main class hello.world.HelloWorld
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
But when I run file HelloWorld.java, it does it fine
I am doing this on Netbeans IDE 7.2
Rather than the coding error, it could be related to IDE. Since the "Run File" runs okay, but 'Run Project" does not, I believe you have something to set up in IDE itself. Right click the project, and select "Set is as Main", now run the project. I am just giving it a guess, may not help you. But it worth a shot.If it does not help, please paste your code too.
Your class needs a public static void main(String[] args) function. And moreover I suspect that the error could be in the package.
If you want your class in <main_package>.<sub_package>, The directory structure is
- main_package
- sub_package
-HelloWorld.java
And be sure to write your class like this.
package main_package.sub_package;
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hello " + args[o]);
}
}
This is all due to the naming convention in Java
You need to run the .class file containing the public static void main(String[] args) method..
Here, your HelloWorld.java file might contain a class with main() method.. So, you can run it..
This is because, execution of any Java program starts with the invocation of main().. JVM needs an entry point to your code.. Which is main().. If it doesn't find one.. It will not run..
So, make sure, whatever class file you are running, it should have main() method..
UPDATE :- And for the starting point, may be you can skip using packages.. Just go with plain Java class without packages..
This message can also appear in Eclipse (Juno 4.2.2 in my case) and I have found two potential causes for it.
In my cases:
1. a DTD was in error. I deleted the file and that solved the issue*.
2. having cleaned the project, an external Jar that I had built externally had been deleted as could be seen from Properties -> Java Build Path -> Libraries.*
*Having solved either of the above issues, it was necessary to restart Eclipse
if you are using intellij idea then just rebuilding (clean and build) project might solve your problem . because intellij might be still trying to load the old classes which are not there or changed
Make sure you call looks like below:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello user");
}
}
To run a Java class in stand alone mode, public static void main(String[] args) is the entry method, which is must.
I am getting a ClassNotFOundException while running a code.I am using Eclipse.
Although it has main method with proper arguments it is still not able to launch the code.
Package name and import is also correct.
public class TestNew {
public static void main(String[] args)
{
ArrayList<String> sumList=new ArrayList<String>();
Cm cm=new Cm();
sumList=cm.sumListCombo();
for(int i=0;i<=sumList.size();i++)
{
System.out.println(sumList.get(i));
}
}
}
Import of respective packages are done.
Try refreshing the Project, then clean it and build it. If there is no problems, your code will work. If there is a problem, it will be some kind of 'Organize Imports' issue. Ctrl+Shift+o and you are ready.
Try Ctrl + Shift + O if you're on windows.
This organizes your imports(adds missing ones and removes unnecessary ones).
Then on the menu bar, Project >> Clean...
Then re-launch your app.