edvin / tornadofx

Lightweight JavaFX Framework for Kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AsyncKt cannot access class com.sun.glass.ui.Application

mirkarlar opened this issue · comments

When trying to execute an async restcall I get the following exeption.

class tornadofx.AsyncKt (in module tornadofx) cannot access class com.sun.glass.ui.Application (in module javafx.graphics) because module javafx.graphics does not export com.sun.glass.ui to module tornadofx
at tornadofx@1.7.20/tornadofx.AsyncKt.success(Async.kt:115)
at tornadofx@1.7.20/tornadofx.Component.ui(Component.kt:240)

pom and module-info.java added (with extention .txt to allow them to be attached)
pom.xml.txt
module-info.java.txt

tried different jdk's: openjdk 11.0.7 , corretto (amazon) 15.0.2
different versions for javafx: 17-ea+11/ 18-ea+7

any help appreciated

additional info:
Controller with restcall (calling the function directly returns desired results):

class ForecastController : Controller() {

    val selectedCity: CityModel by inject()

    var allWeather = FXCollections.emptyObservableList<ForecastList>()

    val api: Rest by inject()

    init {
        api.baseURI = "https://api.weatherbit.io/v2.0/forecast/daily/"

    }

    fun listForcast(cityName: String = selectedCity.name.value, countryName: String = selectedCity.country.value) : List<ForecastList>
            =  api.get("?City=$cityName&country=$countryName&key=$appId").list().toModel<ForecastList>()

}

Async call:

setOnKeyPressed {
                            if (it.code == KeyCode.ENTER) {
                                tornadofx.runAsync {
                                    controller.allWeather = controller.listForcast(
                                        cityName = controller.selectedCity.name.value,
                                        countryName = controller.selectedCity.country.value
                                    ) as ObservableList<ForecastList>?
                                } ui {
                                    forecastList = controller.allWeather[0]
                                    vbox {
                                        cityLabel.text = forecastList.city.name

                                    }

                                }
                            } else {
                                null
                            }
                        }

made a bit of headway:

Instead of adding the VM option: --add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
using --add-exports javafx.graphics/com.sun.glass.ui=tornadofx
seems to be working

IntelliJ RunConfiguration screenshot:
Screenshot_20211202_230158
g

Yes welcome to the Java module system rolls eyes.

You should probably apply these VM options via your build tool. My build gradle has this for example:

image

Most of them are there to make JFoenix work but I plan to replace it entirely with the newer MaterialFX.

you are using version 1.7.20, you need 2.0.0-SNAPSHOT.

1.7.20 - java8
2.0.0 - java11+

you are using version 1.7.20, you need 2.0.0-SNAPSHOT.

1.7.20 - java8 2.0.0 - java11+
Thnx for your reply.

Upgrading to 2.0.0 (SNAPSHOT) didn´t fix this problem.
Still upgrading fixed some other issues, and I'm quite happy with it.

The jvm options to loosen the module restrictions fixed the export errors.

Weird thing is
-add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED,
which should be more general, didnt work. Instead I had to use
--add-exports javafx.graphics/com.sun.glass.ui=tornadofx

For now I can work with that, but still makes me scratch my head....

made a bit of headway:

Instead of adding the VM option: --add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
using --add-exports javafx.graphics/com.sun.glass.ui=tornadofx
seems to be working

IntelliJ RunConfiguration screenshot:
Screenshot_20211202_230158
g