Ask coding questions

← Back to all posts
Java Swing Compile bug
slump3301 (2)

I've recently started learning the swing framework for java and have been playing around with it. I've noticed that sometimes the code wont re-compile before executing such as in a regular java REPL. This isn't because of the presence of .class files since I delete them all before running the REPL with new changes. Is there anyway I can force my program to re-compile? Or is there any command I can enter into the shell terminal opened with the command palette so that it would compile going through all of the proper run directories?

The console tells me that it cannot find a class and the class it cannot find sometimes changes. I found out through the terminal that there are still some .class files left over but they don't show up in the file tab.

edit: I have figured out the issue. If there is an error in your code the program will ignore it and attempt to continue running which causes the program to have the class not found exceptions. a simple way to check what the error is for anyone who is experiencing this: in the Linux terminal opened through the command palette, type in "javac ./" except replace "filepath" with the file path.

brendandilloughery (0)

I just have to say thank you. This post fixed all my problems. The Java Swing auto-recompile is not working at all. The two main problems:
1. If you edit other classes than the JFrame/JPanel/Main, the changes don't usually get recompiled unless you edit one of those 3 mentions (even just deleting and retyping a word)
2. If you delete a class file and press play, as you said it might have an error compiling, and rather than displaying the error it just does not compile and tells you it can't find the class file.

Typing in "java *.java" in the console window to manually recompile all java files in the main directory solved all my problems. Didn't even think to use direct console access like that - duh!

slump3301 (2)

resolved in edit

SixBeeps (1970)

Intriguing. Could you link your REPL so that we can take a look at it?

slump3301 (2)

@niorg2606 here:
This doesn't happen everytime which is why I suspect it is only a bug.