I am writing a javafx program and I need the panel to update at a constant rate. Right now it is set to update every second. But I got this error, which is usually (but not always) followed by a glitch in the panel when the whole scene becomes distorted (it like mirrors in on itself in a weird choppy x pattern. hard to explain).
Full error: (java:22494): Gdk-WARNING **: 18:38:59.118: XSetErrorHandler() called with a GDK error trap pushed. Don't do that.
This is the code I have for the timer:
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
String x = txtDisplay.getText();
txtDisplay.setText(x.substring(1, x.length()) + x.substring(0, 1));
} catch (NullPointerException e) {
System.out.println("Error.");
}
}
});
}
}, 0, 500);
I think the issue is with the above block, like maybe I am breaking some fundamental swing rule. My other idea is that it has something with two methods editing the same text area at the same time, because I have other methods setting the text area's text.
I would be happy with either a solution to the error or a better way of executing the above method. Just needs to run every second without crashing.
Thanks.
EDIT: A new developement, I am now consistently getting a "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" but the stacktrace does not reference any locations that are in my code.
javax.swing.Timerfor UI related tasks and ajavax.swing.SwingWorkerfor background tasks. For JavaFX, you'd use the animation API for UI related tasks and ajavafx.concurrent.Workerfor background tasks.