java - javafx 8 compatibility issues - FXML static fields -


i have designed javafx application works fine in jdk 7. when try run in java 8 getting below exceptions:

javafx.fxml.loadexception:  @ javafx.fxml.fxmlloader.constructloadexception(fxmlloader.java:2617)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2595)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2441)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3230)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3191)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3164)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3140)     @ javafx.fxml.fxmlloader.load(fxmlloader.java:3132)   exception in thread "javafx application thread" java.lang.nullpointerexception: root cannot null     @ javafx.scene.scene.<init>(scene.java:364)     @ javafx.scene.scene.<init>(scene.java:232)         @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:86)     @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238)     @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191)     @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58)     @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114)     @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74)     @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:54)     @ javafx.event.event.fireevent(event.java:204)     @ javafx.concurrent.eventhelper.fireevent(eventhelper.java:219)     @ javafx.concurrent.task.fireevent(task.java:1357)     @ javafx.concurrent.task.setstate(task.java:720)     @ javafx.concurrent.task$taskcallable$2.run(task.java:1438)     @ com.sun.javafx.application.platformimpl$6$1.run(platformimpl.java:301)     @ com.sun.javafx.application.platformimpl$6$1.run(platformimpl.java:298)     @ java.security.accesscontroller.doprivileged(native method)     @ com.sun.javafx.application.platformimpl$6.run(platformimpl.java:298)     @ com.sun.glass.ui.invokelaterdispatcher$future.run(invokelaterdispatcher.java:95)     @ com.sun.glass.ui.win.winapplication._runloop(native method)     @ com.sun.glass.ui.win.winapplication.access$300(winapplication.java:39)     @ com.sun.glass.ui.win.winapplication$4$1.run(winapplication.java:112)     @ java.lang.thread.run(thread.java:744) 

i found out reason in initialize method of controller class not able use inbuilt methods in static component. (for example: staticmytextfield.settext() causing problem in java 8 not in java 7). not able find out documented regarding in javafx guides. can please provide ideas on why causing issue in java 8? , share documents related if any.

it sounds trying inject textfield static field. like

@fxml private static textfield mytextfield ; 

this apparently worked in javafx 2.2. doesn't work in javafx 8. since no official documentation ever supported use, it's doesn't violate backward compatibility, though in fairness documentation on fxmlloader pretty woeful.

why ever want though? it's terrible idea. suppose decided reuse fxml file twice in same application: second use overwrite value static field, , sorts of chaos ensue. put, if trying have static fields injected in controller, you're doing things wrong anyway.

update: response question in comments

in particular, don't use static fields enable them accessible outside class. static field has single value belonging class, instead of value each instance of class, , decision make fields static should made if makes sense. allow access instance data, have have reference instance. fxmlloader has getcontroller() method allows retrieve reference controller.

a related point: it's not idea expose ui controls controller. should instead expose data. example, instead of defining gettextfield() method in controller, instead define textproperty() method returns stringproperty representing contents of textfield. reason when boss comes office , tells wants textfield replaced textarea, or combobox<string>, or other control, it's going lot harder if classes outside of controller using textfield. structure of data represented controller less change implementation of how data presented user.

for examples


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -