Fehlermeldung bei Validierung mit controlsfx

Baerdoc

Mitglied
Eine Verständnisfrage an die Profis:
Ich habe für eine JavaFX-Anwendung eine Validierung der Eingafelder über die Einbindung der Bibliothek controlsfx-11.2.0.jar realisiert.
Als Beispiel sollen 2 Textfelder auf fehlende Eingabe geprüft werden. Wenn ich 2 Instanzen der Klasse ValidationSupport erzeuge, läuft der Code fehlerfrei und die Eingabefelder werden überprüft.

Version I
Java:
ValidationSupport validationSupport1 = new ValidationSupport();
ValidationSupport validationSupport2 = new ValidationSupport();     

@FXML
private TextField nachnameTF; 

 @FXML
private TextField vornameTF;

...

private void validierungTextfelder() {
    validationSupport1.registerValidator(nachnameTF,Validator.createEmptyValidator("Pflichtfeld"));
    validationSupport2.registerValidator(vornameTF, Validator.createEmptyValidator("Pflichtfeld"));
}

Wenn ich die beiden Textfelder über 1 Instanz von ValidationSupport prüfen will (ich bilde mir ein, es so schon mal irgendwo gelesen zu haben), wird u.g. Fehler geworfen, die Überprüfung der Eingabefelder funktioniert jedoch weiterhin problemlos und die Anwendung läuft weiter.

Version II
Java:
ValidationSupport validationSupport = new ValidationSupport();     

@FXML
private TextField nachnameTF; 

 @FXML
private TextField vornameTF;

...

private void validierungTextfelder() {
    validationSupport.registerValidator(nachnameTF,Validator.createEmptyValidator("Pflichtfeld"));
    validationSupport.registerValidator(vornameTF, Validator.createEmptyValidator("Pflichtfeld"));
}

Exception bei Version II
Code:
Exception in thread "JavaFX Application Thread" java.lang.reflect.InaccessibleObjectException: Unable to make protected javafx.collections.ObservableList javafx.scene.Parent.getChildren() accessible: module javafx.graphics does not "opens javafx.scene" to unnamed module @5fc2db79
    at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:391)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:367)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:315)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:203)
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:197)
    at impl.org.controlsfx.ImplUtils.getChildrenReflectively(ImplUtils.java:148)
    at impl.org.controlsfx.ImplUtils.getChildren(ImplUtils.java:125)
    at org.controlsfx.control.decoration.GraphicDecoration.applyDecoration(GraphicDecoration.java:115)
    at impl.org.controlsfx.skin.DecorationPane.showDecoration(DecorationPane.java:74)
    at impl.org.controlsfx.skin.DecorationPane.addAllDecorationsOnNode(DecorationPane.java:119)
    at impl.org.controlsfx.skin.DecorationPane.updateDecorationsOnNode(DecorationPane.java:70)
    at org.controlsfx.control.decoration.Decorator.lambda$updateDecorationsOnNode$0(Decorator.java:165)
    at org.controlsfx.control.decoration.Decorator.lambda$getDecorationPane$1(Decorator.java:205)
    at org.controlsfx.control.decoration.Decorator$1.invalidated(Decorator.java:223)
    at javafx.base@21.0.2/com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:147)
    at javafx.base@21.0.2/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:91)
    at javafx.base@21.0.2/javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:80)
    at javafx.base@21.0.2/javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
    at javafx.graphics@21.0.2/javafx.scene.Node$ReadOnlyObjectWrapperManualFire.fireSuperValueChangedEvent(Node.java:1044)
    at javafx.graphics@21.0.2/javafx.scene.Node.invalidatedScenes(Node.java:1095)
    at javafx.graphics@21.0.2/javafx.scene.Node.setScenes(Node.java:1133)
    at javafx.graphics@21.0.2/javafx.scene.Parent.scenesChanged(Parent.java:773)
    at javafx.graphics@21.0.2/javafx.scene.Node.invalidatedScenes(Node.java:1066)
    at javafx.graphics@21.0.2/javafx.scene.Node.setScenes(Node.java:1133)
    at javafx.graphics@21.0.2/javafx.scene.Parent.scenesChanged(Parent.java:773)
    at javafx.graphics@21.0.2/javafx.scene.Node.invalidatedScenes(Node.java:1066)
    at javafx.graphics@21.0.2/javafx.scene.Node.setScenes(Node.java:1133)
    at javafx.graphics@21.0.2/javafx.scene.Parent.scenesChanged(Parent.java:773)
    at javafx.graphics@21.0.2/javafx.scene.Node.invalidatedScenes(Node.java:1066)
    at javafx.graphics@21.0.2/javafx.scene.Node.setScenes(Node.java:1133)
    at javafx.graphics@21.0.2/javafx.scene.Scene$8.invalidated(Scene.java:1244)
    at javafx.base@21.0.2/javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
    at javafx.base@21.0.2/javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:147)
    at javafx.graphics@21.0.2/javafx.scene.Scene.setRoot(Scene.java:1196)
    at javafx.graphics@21.0.2/javafx.scene.Scene.<init>(Scene.java:360)
    at javafx.graphics@21.0.2/javafx.scene.Scene.<init>(Scene.java:211)
    at com.itmedizin.main.StartDOT.initStartLayout(StartDOT.java:35)
    at com.itmedizin.main.StartDOT.start(StartDOT.java:27)
    at javafx.graphics@21.0.2/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
    at javafx.graphics@21.0.2/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
    at javafx.graphics@21.0.2/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at javafx.graphics@21.0.2/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
    at javafx.graphics@21.0.2/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at javafx.graphics@21.0.2/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@21.0.2/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)
    at java.base/java.lang.Thread.run(Thread.java:1583)

(Die Bibliothek controlsfx-11.2.0.jar ist über den Classpath eingebunden. Es gibt keine module-info.java. Java-Version 21.0.2)
Version I läuft zwar, mich würde aber interessieren, warum Version II einen Fehler ausgibt, aber trotzdem fubktioniert.
 
Da steht, dass es kein ObservableList erstellt werden kann, weil es auf javafx.scene.Parent.getChildren(); keinen Zugriff gibt.
Du sagst, nach zweimaligen Verwendung vom ValidationSupport-Objekt tritt dieser Fehler auf, den Zusammenhang kannst du nur in der ValidationSupport Dokumentation herausfinden, ich habe fx noch nicht eingerichtet.
Meine Vermutung wäre, dass alle Objekte in ein Set landen, wo sie sich nicht wiederholen dürfen.
 
Zuletzt bearbeitet:
Ich habe jetz mal ein Code-Fragment aus dem Netzt gefunden:
Java:
    ValidationSupport validationSupport = new ValidationSupport();
    Platform.runLater( () -> {
      String requiredFormat = "'%s' is required"; //$NON-NLS-1$
      validationSupport.registerValidator(txUserName, Validator.createEmptyValidator( String.format( requiredFormat, userNameCation )));
      validationSupport.registerValidator(txPassword, Validator.createEmptyValidator(String.format( requiredFormat, passwordCaption )));
//            loginButton.disabledProperty().bind(validationSupport.invalidProperty());
      txUserName.requestFocus();
    } );

Demnach müsste Version II mit einer Objektinstanz von ValidationSupport eigentlich auch funktionieren. Warum bei mir keine ObservableList erstellt werden kann, habe ich allerdings bisher nicht ergründen können.
 
Generell ist eine Möglichkeit, Module auf der Kommandozeile zu öffnen und so. Siehe dazu z.B.:

Also bei dir wäre beim javac ein Parameter --add-opens javafx.graphics/javafx.scene=ALL-UNNAMED den Du einfügen könntest.

Wobei ich mich gerade frage, wieso in javafx.graphics ein Package javafx.scene ist. Das würde ich eigentlich im javafx.scene Modul erwarten. Aber ich habe jetzt gerade keine Möglichkeit, da in das jar zu schauen.
Edit: Da hatte ich einen "Dreher" im Kopf. Den Punkt kannst Du vergessen...
 

Zurück
Oben