Usually I know what the problem is or how to describe it. But this is just beyond my understanding.
I have a set of public static variables in my main class, the first thing that happens in the main(String[] a) method of the project is displaying two of those. But for some reason when I changed it in the declaration, the program still runs of the old one. I have attempted removing the static and calling them from within the method with the same result. As far as I can test all variables in this section of the program suffer from the same problem.
Here is the screenshot of the code and variable (I made a break point on the main method just to be sure nothing else runs):
In case this matters, I have actually changed computers since the last version of the app, I have a new installation of everything but I rebuild all directories as they were and besides this variable change (or lack there of) everything runs with no issues.
Ok it took a bit of thinking outside of the box but I've fixed it (not all steps may be required, but when tried on their own they didn't work):
Close all tabs (files) in Eclipse
Close Eclipse
Open and save (without editing) the .java file in other program (like Notepad++)
Open Eclipse
Right-Click inside Package Explorer and 'Refresh' (or use F5)
Open the file and build the project
It's a very strange bug and I hope if someone else finds it the 'fix' will work for them.
Related
I've used IntelliJ and VSC before, both of which had nice one-button solutions to compile and run, even going as far as having keyboard shortcuts for it as well. But unfortunately, for reasons I'm not in the mood to get into right now, and cannot change, I have to use BlueJ for certain projects in my class.
Don't get me wrong, I actually do like using BlueJ on simpler and smaller projects with it's simple interface, but one thing that really limits the speed I work at is having to hit "Compile", right-clicking the tester class, clicking "void main", and then hitting "Okay", EVERY single time I want to test the code. It's sluggish and takes infinitely longer than one button or a keyboard shortcut.
Is there any way, external modification or otherwise, that I could have a simpler method for compiling and running code in BlueJ? Even saving on one or two of these clicks would be greatly appreciated.
I just recently started trying to work with Java, I have set the path variable and on first try it worked fine, but now whenever I boot I have to go check the variable (not set it again, just open the control panel, Advanced System Options etc... and then close it) to make it work, otherwise it just says it's not recognised as internal command, as if the path variable was actually not set. If I keep working it stays fine but if I don't do anything for about an hour the problem comes up again (without reboot).
This seems like a very weird problem and I have no idea what could cause it.
So I've been following an oracle tutorial on JavaFX and I copied the code EXACTLY. I even went as far as to copy paste it from the text version into my IDE. I'm 100% sure that the code is correct.
The first one I followed was this video series.
The second tutorial I used to ensure that there were no errors in the code and the text version I copied.
In my frustration I decided to go from my desktop to my laptop to work, so I uploaded the faulty code to my online repository and lo and behold! It suddenly worked! Which indicates that I am right about there being no errors in the code. But as soon as I make any changes, it stops working again.
The error messages I receive indicates that it happens inside of the Application I'm extending in my Start.class where I have the main().
I'm using NetBeans as my IDE, and my project is a Maven project.
The answer seems to be that you need to clean the project when you perform changes to the FX parts. Clean before you run it and it will work fine, provided there actually isn't anything wrong with your code.
How can I make it so Eclipse automatically updates my code in a window as I edit it? I've seen the feature before in youtube videos but I cannot find it. For example : I change a JApplet rectangle width from 20 to 10, I want to see it update immediately.
I've seen Notch do this on development videos (Minecraft), it is awesome but I don't know exactly how he does it.
-- EDIT --
This has been bugging me so I went and googled "how does notch code" and found this on a blog page https://gun.io/blog/what-i-learned-from-watching-notch-code/. It doesn't say exactly how it was done but gives a good hint (HotSwap) and makes it seem like he set it up himself without external software. Here's the most relevant section:
Incredibly Fast Testing
He began by building the engine, and to do this he used the ‘HotSwap’ functionality of the Java JVM 1.4.2, which continuously updates the running code when it detects that a class has changed.
When building the engine, Notch wrote a function which would continuously pan the camera around and clip through the walls and keep the view on top, so he could make changes to the code and see the effects they made in real time. I’m used to testing by writing a function, building it, installing it on the device I’m testing on, and then seeing the result, which can take up to a minute at a time, so it’s easy to see how HotSwapping could save a lot of development time.
--- ORIGINAL POST CONTINUED ---
I get a similar effect by using groovysh though, works smoothly and can use all your java classes as is.
What I'll usually do is write all my code in java, then go and fire up "Groovysh" where it will give you a little window to enter commands (You may have to ensure the classpath works correctly outside of eclipse). I can then "new" any of my classes and call methods on them one line at a time. When you do myFrame.setSize([100,100]) you will see it change immediately.
A good test is to just run groovysh and type something like:
import javax.swing.*
f=new JFrame()
f.setVisible(true)
f.setSize(100,100)
or the groovier version:
f=new JFrame(visible:true, size:[100,100])
and you will see your frame resize on the screen. You can even drag it bigger and then do something like:
println f.getWidth()
to show your new width. It's fun to interact this way but it's more complicated if you want to actually change your class definition and see it pick up the change, I have no idea how Notch did that. I looked into it a little--it's possible he was using something like JRebel
It requires something special since you would have to dynamically reload the classfile into your running system on every save--something that should have serious classloader issues.
By the way there is also a way to get your Java program to throw out a little GroovyConsole which will allow you to inspect and modify all the variables in your running code (but again you can't replace definitions of existing classes).
Also see answer here:
Change a method at runtime via a hot swap mechanism
"Debugception!"
You may notice that within the first 15 seconds of this YouTube video (from 1:01:01 to 1:01:16), Markus Persson (aka "Notch", creator of Minecraft) has somehow managed to save/update an application and attach a debugger to it while it was already under the process of being debugged, supposedly all with a simple keyboard shortcut. The previously coded application somehow magically became the newly edited one, and seemingly without relaunching it or spawning a new process... It's possible that this is just some form of locally remote debugging, but something about it just doesn't seem quite right.
I've spent several days Googling and asking around on how he was able to do this, yet to no avail. I've found no such option under Eclipse preferences, and whenever I try to save & debug an already running application, it simply launches a separate instance of the newly updated application, side-by-side with the older, outdated one.
Am I missing something? How was this possible?
How was he able to utilize such an astounding, powerful debugging feature?
Thanks in advance!
Update
Okay, so this appears to be a standard feature specific to Eclipse.
Coming from a background in NetBeans and Visual Studio, I'm astounded that this doesn't seem to exist elsewhere (or at least in NetBeans!)...
This is a built-in feature of Eclipse. If you edit a method while the program is running in debug mode, it will compile the new method, and replace the old method with the new version. If some thread was already running that method, it will jump back to the beginning (AFAIK; this might only happen when the program is paused).
You don't need to re-launch the program or set any special preferences. Just edit and save, and the magic will happen.
Eclipse can't always figure out how to merge your changes into the running program - usually if you changed anything outside a method body (including the method's parameters or return type). In this case, you will get a warning dialog, with the option to stop the program, restart the program or ignore the changes.