不能 运行 JavaFX - Kotlin 应用程序
Can't run JavaFX - Kotlin app
我不能 运行 我的 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 - 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)
}