[英]Can't run JavaFX - Kotlin app
I can't run my javafx - kotlin app. 我无法运行javafx-Kotlin应用程序。
My Starter 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)
}
}
I can't pass the param "args" to "launch" method because compiler says: 我不能将参数“ 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
错误:(19,9)Kotlin:使用提供的参数无法调用以下函数:public open fun launch(p0:Class !, vararg p1:String!):javafx.application.Application中定义的单元launch(vararg p0:String!):在javafx.application.Application中定义的单位
If I trying call "launch" method without params I have following Exception 如果我尝试不带参数调用“启动”方法,则会出现以下异常
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
sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处线程“ main”中的java.lang.reflect.InvocationTargetException异常sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor .java:43),位于java.lang.reflect.Method.invoke(Method.java:498),位于sun.launcher.LauncherHelper $ FXHelper.main(LauncherHelper.java:767),原因:太阳时的java.lang.NullPointerException。在java.lang.reflect.Method.invoke(sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)处的sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)处的Reflection.NativeMethodAccessorImpl.invoke0(本机方法) com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)上的Method.java:498)... com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)上的Method.java:5 ...
You need to use spread operator 您需要使用传播算子
fun main(args: Array<String>) {
Application.launch(Starter::class.java, *args)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.