Controls FX TraversalEngine Error - java

I installed JDK8u20 and tried to run my program with the ControlsFX library in it.
This should work fine, but if I call a method from controlsFX, I get the following exception
Method
private void showError(final String msg) {
Platform.runLater(new Runnable() {
#Override
public void run() {
Dialogs.create().title("Achtung").message(msg).showError();
}
});
}
Exception
java.lang.NoSuchMethodError: com.sun.javafx.scene.traversal.TraversalEngine.<init>(Ljavafx/scene/Parent;Z)V
at org.controlsfx.control.ButtonBar$2.<init>(ButtonBar.java:412)
at org.controlsfx.control.ButtonBar.<init>(ButtonBar.java:412)
at org.controlsfx.control.ButtonBar.<init>(ButtonBar.java:355)
at org.controlsfx.dialog.Dialog.createButtonPanel(Dialog.java:1034)
at org.controlsfx.dialog.Dialog.createCenterPanel(Dialog.java:1029)
at org.controlsfx.dialog.Dialog.buildDialogContent(Dialog.java:950)
at org.controlsfx.dialog.Dialog.show(Dialog.java:320)
at org.controlsfx.dialog.Dialogs.showSimpleContentDialog(Dialogs.java:1106)
at org.controlsfx.dialog.Dialogs.showError(Dialogs.java:555)
at ch.berufsbildungscenter.notiztool.gui.control.LoginController$3.run(LoginController.java:93)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1171794308.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1875594551.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/994750745.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Adding an answer for someone facing the same issue in future :
ControlsFX 8.0.6 was released in two separate releases
ControlsFX 8.0.6, for developers using JavaFX 8.0
ControlsFX 8.0.6_20, for developers building with JavaFX 8u20
If you are wondering why ? here is an explanation to it
If you are using JDK8, go with ControlsFX 8.0.6
If you are using JDK8_20 or later, go with ControlsFX 8.0.6_20

Related

`NullPointerException` on swing AWT thread - cursor update on JLightweightFrame

I have a NullPointerException in my application, that happens only on one specific PC, and is reproducible. I wrote my GUI using Javafx with some Swing JPanels on it via SwingNode.
What should I do?
Exception-Time = 2016-08-30 06:55:50 UTC Exception-Tag = 0 Exception-Message = Thread AWT-EventQueue-0 (Id = 55) throw exception: null Stack-Trace = java.lang.NullPointerException
at sun.swing.JLightweightFrame.updateClientCursor(Unknown Source)
at sun.swing.JLightweightFrame.access$000(Unknown Source)
at sun.swing.JLightweightFrame$1.updateCursor(Unknown Source)
at sun.awt.windows.WLightweightFramePeer.updateCursorImmediately(Unknown Source)
at java.awt.Component.updateCursorImmediately(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
More about the problem:
Apparently, this is a bug at the JDK itself (versions 8 and 9) and probably won't get fixed until JDK10.
This exception is thrown from within the sun.swing.JLightweightFrame.java class, at the updateClientCursor function (lines 472-749):
private void updateClientCursor() {
Point p = MouseInfo.getPointerInfo().getLocation();
SwingUtilities.convertPointFromScreen(p, this);
Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
if (target != null) {
content.setCursor(target.getCursor());
}
}
In general, this is happening because MouseInfo.getPointerInfo() can return NULL, for example, when you move between graphic devices. 'MouseInfo' can still hold the former graphic device information, then getPointerInfo() can return NULL if the mouse already moved to the new graphic device and MouseInfo still didn't updated to the new graphic device information. this scenario will cause a Null Pointer Exception on this line MouseInfo.getPointerInfo().getLocation() for trying to run a method of a NULL object.
For me, NPE is thrown when I move my JavaFX app window between monitors on my multiscreen machine. Its not happening every time but it is reproducible very easily.
I'm using a Swing component in a JavaFX SwingNode component.
This bug is already a known issue at Oracle bug list.
Code Fix:
This snippet shows an optional fix for this bug:
private void updateClientCursor() {
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
if (pointerInfo == null) {
/*
* This can happen when JavaFX cannot decide
* which graphics device contains the current
* mouse position.
*/
return;
}
Point p = pointerInfo.getLocation();
SwingUtilities.convertPointFromScreen(p, this);
Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
if (target != null) {
content.setCursor(target.getCursor());
}
}
Taken from JetBrains repository
Optional solution:
Since it is a bug withing the formal Oracle JDK, there is no much I can do about it. there are fixes applied in other non-formal JDKs like OpenJDK for example, which applied a fix, but I don't know which version will apply this fix yet.
For me, I would probably try to compile and use my own JDK with the applied fix and use it in my project, but this is a hard to maintain and not so flexible solution. If someone have another fix/workaround I would be happy to hear.

JavaFX NullPointerException Location is required NetBeans [duplicate]

This question already has an answer here:
How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?
(1 answer)
Closed 2 years ago.
i've tried anything else i found on stack stackoverflow and i really dont get it why this doesn't work.
I won't show you the code of my application that is not working, because it isn't working even with the example project.
So here is the problem:
When i create new JavaFX Application with the sample code that gives button which prints hello world after clicked, this works when i run this as a desktop application and when i build this and start in browser. This works perfectly as desktop and as browser application
But when i create new JavaFX FXML Application which is almost the same as above but stage is defined by fxml and css not byte he code. This one works perfectly as windows application but doesnt work as a browser application
java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafxapplication3.JavaFXApplication3.start(JavaFXApplication3.java:22)
at com.sun.javafx.applet.FXApplet2$2.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/15592694.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/19532686.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$35/9825943.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.NullPointerException: Location is required.
at com.sun.javafx.applet.FXApplet2$2.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/15592694.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/19532686.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$35/9825943.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafxapplication3.JavaFXApplication3.start(JavaFXApplication3.java:22)
... 11 more
here is the code of working application:
public class JavaFXApplication4 extends Application {
#Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
and this application doesnt work in browser and throws exception:
public class JavaFXApplication3 extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Can someone help me?
The problem is in this line:
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
It is pretty clear that the load method is actually being called with a null argument. And that happens because getResource("/sample/sample.fxml") cannot file that resource.
The resource is missing (or has the wrong path) on the runtime classpath.
Source
The problem has to do with signing but I do not exactly understand what that means. Then I searched for how to run a JavaFX application in a browser with netbeans and found this: http://docs.oracle.com/javafx/2/fxml_get_started/fxml_deployment.htm
In netbeans 8.2 in the project properties under Build > Deployment there is a check-box:
Request unrestricted access (Enable signing)
With this it works. Good luck.
In some case, if you using maven you should move all your fxml files to the resources directory and use a relative address from there.
If you want to use stage.setScene() function inside a controller class, it's better to use:
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
if u are using different packages then cut that file from other package and paste it in main package. And then try to run . I have tried that approach and its working fine now .

JavaFX Text in/on Polygon

I wanted to take a text (javafx.scene.text) and put it on a polygon.
I tried it with a Group (javafx.scene.group) by trying this tutorial: tutorial on stackoverflow
This doesn't work with the text.setClip(Polygon).
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at ch.berufsbildungscenter.notiztool.gui.control.BbcPolygon$1.run(BbcPolygon.java:33)
at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)
at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Is there another way to get a Text onto a polygon?
Thanks
Peace
setClip() has different purpose. You can check the documentation To easily put Text on a Polygon or any other node, you can use javafx.scene.layout.StackPane like this: StackPane stack=new StackPane();
stack.getChildren().add(polygonInstance);
stack.getChildren().add(textInstance); The node last added will be on top.

MATLAB reports "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"

I wonder about a Java error that is repeatedly occurs in MATLAB. It typically occurs when MATLAB is doing some heavy stuff with Java. This can for example be holding Ctrl + Z or Ctrl + Y.
I did by mistake erase the error message before I copied it, but I think that I can pass the core of the problem anyway.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
...
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Why did this error occur? I have found some information about this from MATLAB r2007, this due to that Java Swing is thread unsafe and MATLAB lacked support to ensure thread safety. However, that is supposed to have been fixed in MATLAB r2008b. So why do I get it now?
Here is the full stack trace:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.netbeans.editor.BaseDocument.notifyUnmodify(BaseDocument.java:1465)
at org.netbeans.editor.BaseDocument.notifyModifyCheckEnd(BaseDocument.java:816)
at org.netbeans.editor.BaseDocumentEvent.redo(BaseDocumentEvent.java:336)
at javax.swing.undo.UndoManager.redoTo(Unknown Source)
at javax.swing.undo.UndoManager.redo(Unknown Source)
at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)
at org.netbeans.editor.ActionFactory$RedoAction.actionPerformed(ActionFactory.java:767)
at org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:259)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at com.mathworks.widgets.SyntaxTextPaneBase.processKeyEvent(SyntaxTextPaneBase.java:1187)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Well, based on your stack trace, probably there isn’t any definitive answer to your question, as you have already seen in MATLAB's forum, but given this line, I think there's a possible explanation:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
...
at javax.swing.undo.UndoManager.redoTo(Unknown Source) // <-- here!
at javax.swing.undo.UndoManager.redo(Unknown Source)
at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)
...
UndoManager class keeps an internal collection of UndoableEdit objects. This collection is actually inherithed from its superclass: CompoundEdit.
The internal implementation of UndoManager#redo() and UndoManager#redoTo(UndoableEdit edit) looks like this:
public class UndoManager extends CompoundEdit implements UndoableEditListener {
...
public synchronized void redo() throws CannotRedoException {
if (inProgress) {
UndoableEdit edit = editToBeRedone();
if (edit == null) {
throw new CannotRedoException();
}
redoTo(edit);
} else {
super.redo();
}
}
...
protected void redoTo(UndoableEdit edit) throws CannotRedoException {
boolean done = false;
while (!done) {
UndoableEdit next = edits.elementAt(indexOfNextAdd++);
next.redo(); // NPE here?
done = next == edit;
}
}
...
}
Considering this implementation and given that Swing's Event Dispatch Thread (EDT) is prone to cause troubles, I think it's probably a threading issue between MATLAB threads and the EDT. Specifically speaking this MATLAB-invoked method could be the source of the problem:
at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)
Since you say MATLAB needs to do heavy work, it's not unreasonable to think this method is trying to redo some edit that might well not be available anymore or might not be available yet, due to synchronization problems with the EDT.
You can find the ~/.matlab folder which contains MATLAB settings, etc. Use ls -la to show all hidden files and folders.
Open a terminal and execute sudo chmod 757 -R ~/.matlab.
Similarly there is a folder, MATLAB, in Documents.
Execute sudo chmod 757 -R ~/Documents/MATLAB.
Now restart MATLAB without root privileges. It worked for me on Ubuntu 14.04 (Trusty Tahr) and MATLAB 2015a.

NullPointerException when using JavaFX

I am facing a NullPointerException and I can't figure out where or why it occurs. I'm using JavaFX for a project, and it contains a .fxml file which has lots of components (mostly SVGPaths, Circle objects and Text objects). They are imported into a Controller class. Each SVGPath has a mouse listener (for click, enter and exit actions) and sometimes I get a NullPointerException that makes me crazy because I have spent hours trying to solve it. Here is the exact stack trace of exception.
java.lang.NullPointerException
at com.sun.javafx.sg.prism.NGTextHelper.computeBoundsLogical(Unknown Source)
at com.sun.javafx.sg.prism.NGTextHelper.computeContentBounds(Unknown Source)
at javafx.scene.text.Text.impl_computeGeomBounds(Unknown Source)
at javafx.scene.Node.updateGeomBounds(Unknown Source)
at javafx.scene.Node.getGeomBounds(Unknown Source)
at javafx.scene.Node.getLocalBounds(Unknown Source)
at javafx.scene.Node$MiscProperties$2.computeBounds(Unknown Source)
at javafx.scene.Node$LazyBoundsProperty.get(Unknown Source)
at javafx.scene.Node$LazyBoundsProperty.get(Unknown Source)
at javafx.scene.Node.getBoundsInLocal(Unknown Source)
at com.sun.javafx.scene.control.skin.TextAreaSkin$ContentView.layoutChildren(Unknown Source)
at javafx.scene.Parent.layout(Unknown Source)
at javafx.scene.Parent.layout(Unknown Source)
at javafx.scene.Parent.layout(Unknown Source)
at javafx.scene.Scene.layoutDirtyRoots(Unknown Source)
at javafx.scene.Scene.doLayoutPass(Unknown Source)
at javafx.scene.Scene.access$3900(Unknown Source)
at javafx.scene.Scene$ScenePulseListener.pulse(Unknown Source)
at com.sun.javafx.tk.Toolkit.firePulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$3$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:722)
I will appreciate it a lot if someone can help and also explain the reason of this occurrence.
Probably you already solved this, but maybe my solution will help others.
If you are working with JavaFX in a Swing Application you have to be careful to only execute JavaFX code in the correspondent thread and to run Swing code only in the EDT.
I was having a similar problem in my application and it was due to the execution of JavaFX code in the EDT. So, to correct this, I reviewed the code to ensure the use of Platform.runLater(...) on methods that were possibly called from the EDT.
Platform.runLater(new Runnable() {
#Override
public void run() {
// JavaFX manipulation code.
}
}
This seems easy but can be tricky to remember sometimes. So, to be sure, review your JavaFX code searching for public methods and interfaces that can be invoked by Swing components and events.

Categories