TornadoFX找不到JavaFx
我正在尝试使用TotrnadoFx的第一个应用程序,所以我开始使用这个代码:
package no.tornado.fxsample.workspace import javafx.application.Application import tornadofx.* fun main(args: Array) = launch(args) class MyApp: App(MyView::class) class MyView: View() { override val root = VBox() init { with(root) { this += Button("Press Me") this += Label("Waiting") } } }
但显然它充满了错误,并没有能够findJavaFX
我的gradle.build
是:
// set up the kotlin-gradle plugin buildscript { ext.kotlin_version = '1.1.60' repositories { mavenLocal() // mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } // apply the kotlin-gradle plugin apply plugin: "kotlin" // add kotlin-stdlib dependencies. repositories { mavenLocal() // mavenCentral() } dependencies { //dependencies from a remote repositor compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "no.tornado:tornadofx:1.7.12" } jar { manifest { //Define mainClassName as: '[your_namespace].[your_arctifact]Kt' attributes ('Main-Class': 'MyAppKt', "Implementation-Title": "Gradle", "Implementation-Version": 1) } // NEW LINE HERE !!! from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } } sourceSets { main.kotlin.srcDirs += 'src/kotlin' main.resources.srcDirs += 'src/resources' } kotlin { experimental.coroutines 'enable' } compileKotlin { kotlinOptions.jvmTarget= 1.8 // optional, Minimum jvmTarget of 1.8 needed since Kotlin 1.1 kotlinOptions.suppressWarnings = true }
也许你正在使用OpenJDK,默认情况下没有JavaFX? 我强烈建议您安装Oracle JDK 8。
你的代码使用了一些严重过时的语法。 因为你是一个新用户,我怀疑我们有一些过时的代码样本,你能告诉我你在哪里find这些例子吗?
这是现在应该写的:
class MyView : View() { override val root = vbox { button("Press me") label("Waiting") } }
这是一个替代选项,我只是把它写成答案,以防某些人对此感兴趣。 下面的代码现在与我一起使用command line
与MS VS Code
:
main.kt
:
import javafx.* import javafx.application.Application import javafx.scene.control.Button import javafx.scene.layout.VBox import tornadofx.* import javafx.scene.control.Label class MyApp: App(MyView::class) class MyView : View() { override val root = vbox { button("Press me") label("Waiting") } } fun main(args: Array) { Application.launch(MyApp::class.java, *args) }
build.gradle
:
// set up the kotlin-gradle plugin buildscript { ext.kotlin_version = '1.1.60' repositories { mavenLocal() // mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } // apply the kotlin-gradle plugin apply plugin: "kotlin" // add kotlin-stdlib dependencies. repositories { mavenLocal() // mavenCentral() } dependencies { //dependencies from a remote repositor compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "no.tornado:tornadofx:1.7.12" } jar { manifest { //Define mainClassName as: '[your_namespace].[your_arctifact]Kt' attributes ('Main-Class': 'MainKt', "Implementation-Title": "Gradle", "Implementation-Version": 1) } // NEW LINE HERE !!! from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } } sourceSets { main.kotlin.srcDirs += 'src/kotlin' main.resources.srcDirs += 'src/resources' } kotlin { experimental.coroutines 'enable' } compileKotlin { kotlinOptions.jvmTarget= 1.8 // optional, Minimum jvmTarget of 1.8 needed since Kotlin 1.1 kotlinOptions.suppressWarnings = true }
输出是:
但是在Intellij IDEA中仍然存在如下错误:
提到这个它通过添加这个插件与Intellij Idea合作:
apply from: "http://dl.bintray.com/content/shemnon/javafx-gradle/8.1.1/javafx.plugin"
不幸的是,这个插件不再维护 🙁
更奇怪的是,这个代码只需要一次,之后可以删除,没有任何错误,可能是在某个地方兑换的!
- SpringBoot ArrayIndexOutOfBoundsException MethodParameter.getGenericParameterType
- 如何检查字符串不等于一个字符串,那么它将工作,否则没有? 在kotlin
- Java和Kotlin中的共享接口之间的关系(例如:List <>)
- Kotlin:使用lambda代替function界面?
- Kotlin映射&减少字符串的数组映射到<String,Any!>
- kotlin翻新 – 背景粘性并发标记扫描GC释放65326(1448KB)AllocSpace对象,62(1736KB)LOS对象,
- 解析xml kotlin android
- Kotlin的generics和抽象类
- 尝试在Android Studio 2.2.1中运行新项目时出错
- 所有字段和参数都需要@NotNull和@Nullable标注?
- Android Studio 3.0未解决的参考:SupportedLanguages for AIConfiguration类在Dialogflow(api.ai)