我是JavaFX和TornadoFX的新手,但我认识Kotlin。我正在开发新的桌面应用程序,并且正在尝试TornadoFX。我在TornadoFX中安装了IntelliJ插件,并创建了一个新的TornadoFX项目(基于gradle)。在使用模板代码时,当我运行该应用程序时,会得到以下错误:
Jan 28, 2020 4:06:22 PM tornadofx.DefaultErrorHandler uncaughtException
SEVERE: Uncaught error
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
at com.sun.javafx.application.LauncherImpl$$Lambda$49/458209687.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodError: javafx.stage.Window.getProperties()Ljavafx/collections/ObservableMap;
at tornadofx.FXKt.setAboutToBeShown(FX.kt:663)
at tornadofx.App.start(App.kt:84)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$52/707342127.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1637506559.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1602612637.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/2117255219.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)MyApp类: class MyApp: App(MainView::class, Styles::class)
样式类:
class Styles : Stylesheet() {
companion object {
val heading by cssclass()
}
init {
label and heading {
padding = box(10.px)
fontSize = 20.px
fontWeight = FontWeight.BOLD
}
}
} MainView类:
class MainView : View("Hello TornadoFX") {
override val root = hbox {
label(title) {
addClass(Styles.heading)
}
}
}我正在使用java 1.8、kotlin 1.3和tornadofx 1.7.17,我还尝试创建一个新的"Application“配置来运行该应用程序。
任何帮助都是非常感谢的。
发布于 2020-05-28 14:54:19
由TornadoFX插件生成的gradle配置已经过时,并存在许多问题。这不仅是因为为kotlin和tornadofx选择了较早的版本,而且对于使用gradle的kotlin应用程序也不推荐使用buildscript方法。此外,gradle版本非常老,必须进行更新才能使用更新的Java版本。
要从TornadoFX向导和Java 8创建的演示应用程序开始运行构建,请执行以下操作:
sed -i 's/\x0D$//' gradlewMac/Linux:./gradlew run
Windows:gradlew.bat run
Mac/Linux:./gradlew wrapper
Windows:gradlew.bat wrapper
JDK 8 build.gradle
plugins {
// Apply the Kotlin JVM plugin to add support for Kotlin.
id 'org.jetbrains.kotlin.jvm' version '1.3.70'
// Apply the application plugin to add support for building a CLI application.
id 'application'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
// Align versions of all Kotlin components
implementation platform('org.jetbrains.kotlin:kotlin-bom')
// Use the Kotlin JDK 8 standard library.
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
// Use the tornadofx
implementation "no.tornado:tornadofx:1.7.20"
}
mainClassName = "com.example.demo.app.MyApp" JDK 9+
对于JDK 9+,从上面的步骤2开始,然后修改build.gradle以下载JavaFX,因为它与JDK是从9开始的。
添加到插件部分:
// Apply the javafx plugin
id 'org.openjfx.javafxplugin' version '0.0.8'然后添加javafx部分:
javafx {
version = "13"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}最后,将tornadofx版本更改为2.0快照
// Use the tornadofx
implementation "no.tornado:tornadofx:2.0.0-SNAPSHOT"此时,演示应用程序应该运行。在使用9+运行JDK TornadoFX版本时存在一些问题,但是您应该能够在其他问题中找到这些答案。
https://stackoverflow.com/questions/59958943
复制相似问题