Tornadofx: JAVA 11: Getting the View by fxml() return an error.

Created on 23 Aug 2020  路  17Comments  路  Source: edvin/tornadofx

Hello, I have JavaFX Application I started to migrate into TornadoFX.
Q: I have an issue when I want to load an FXML file ( I created it before on the JavaFX)

class LoginView : View() {
override val root:AnchorPane by fxml("/fxml/LoginView.fxml")
}

My LoginView.fxml located on src/main/resources/fxml/LoginView.fxml
Errore: component.javaClass.getResource(resource) must not be null

Note: I am using Maven + Java11 + TornadoFX 1.7.20

Most helpful comment

TornadoFX 1.7.10 doesn't support JDK 9+, you should use the snapshot versions https://github.com/edvin/tornadofx/issues/899#issuecomment-488249680

All 17 comments

Where is the FXML in your project?

Where is the FXML in your project?
In src/main/resources/fxml/LoginView.fxml

you need to make sure that the sourceSet is configured correctly in the maven

you need to make sure that the sourceSet is configured correctly in the maven

   <configuration>
       <sourceDirs>
              <sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
              <sourceDir>${project.basedir}/src/main/java</sourceDir>
     </sourceDirs>
  </configuration

here you also need to set up resources, I'm not a maven expert, so I won't say exactly how

https://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html

I understand that if you do not create a folder, then it will be by default.

How do you launch your cube?

https://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html

I understand that if you do not create a folder, then it will be by default.

How do you launch your cube?

Exactly,
class MyApp: App(LoginView ::class, Styles::class) using TornadoFX configuration run.

 override fun start(stage: Stage) {
        val logins = find(LoginView::class)
        val scene = LoginController.decorator(logins.root, stage)
        stage.scene = scene
        stage.show()
    }

why are you redefining start method?

I found the place from where the error falls out, I did not find another similar one:

1.https://github.com/edvin/tornadofx/blob/master/src/main/java/tornadofx/FX.kt#L114

  1. https://github.com/edvin/tornadofx/blob/master/src/main/java/tornadofx/Component.kt#L195

  2. https://github.com/edvin/tornadofx/blob/master/src/main/java/tornadofx/Component.kt#L1325

and I can only make one conclusion - it doesn't find the file.
The reason may be that there is no jar-file, therefore there are no resources either, try to create a jar and run it (I seemed to have a similar problem, there was a special task in the gradle)

@SchweinchenFuntik
I redfin it because I used FXMLLoader and the FXML has his own fx: controller, and I use JFXDecorator
Thank you for your solution, I'll try a similar solution with Maven.

read the documentation for the method

fxml(location, hasControllerAttribute = true)

JFXDecorator

val scene = LoginController.decorator(logins.root, stage)

what does this method do? Tornadofx has a lifecycle that starts in the start method, overriding it can break a lot of things

  • Yes, I have it did not work too.
  • This adds the content into a JFXDecorator

@AdelDima maybe you don't quite understand how it works.
Below is a ready-made builder and an example of application
https://github.com/bkenn/KFoenix/blob/master/src/main/kotlin/kfoenix/Layouts.kt#L19

i would recommend to run Tornadofx + FXML without JFX first

TornadoFX 1.7.10 doesn't support JDK 9+, you should use the snapshot versions https://github.com/edvin/tornadofx/issues/899#issuecomment-488249680

I somehow overlooked that there is Javafx 11.

https://github.com/edvin/tornadofx/tree/jdk10#snapshots-are-published-to-sonatype

Thank you, I'll use the snapshot.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jordaorodolfo picture jordaorodolfo  路  6Comments

chinzen picture chinzen  路  7Comments

ThraaxSession picture ThraaxSession  路  3Comments

leder11011 picture leder11011  路  5Comments

pavan-p picture pavan-p  路  3Comments