gpt4 book ai didi

javafx - 无法运行 JavaFX - Kotlin 应用程序

转载 作者:行者123 更新时间:2023-12-02 12:48:27 24 4
gpt4 key购买 nike

我无法运行我的 javafx - kotlin 应用程序。

我的初学者类(class)

class Starter : Application() {

override fun start(primaryStage: Stage?) {
val root : Parent = FXMLLoader.load(javaClass.getResource("view/main.fxml"))
primaryStage?.title = "Title"
primaryStage?.scene = Scene(root)
primaryStage?.show()
}

fun main(args: Array<String>) {
launch(args)
}
}

我无法将参数“args”传递给“launch”方法,因为编译器说:

Error:(19, 9) Kotlin: None of the following functions can be called with the arguments supplied: public open fun launch(p0: Class!, vararg p1: String!): Unit defined in javafx.application.Application public open fun launch(vararg p0: String!): Unit defined in javafx.application.Application

如果我尝试在没有参数的情况下调用“launch”方法,我会遇到以下异常

Exception in thread "main" 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:498) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.NullPointerException 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:498) at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) ... 5 more

最佳答案

你需要使用传播运算符

fun main(args: Array<String>) {
Application.launch(Starter::class.java, *args)
}

关于javafx - 无法运行 JavaFX - Kotlin 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47367990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com