2017-11-18 1 views
2

javafx-kotlin 앱을 실행할 수 없습니다.JavaFX - Kotlin app를 실행할 수 없습니다.

초보자 클래스

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) 
    } 
} 

나는 PARAM "인수"를 전달할 수 없습니다에는 "시작"방법은 컴파일러는 말한다 때문에 :

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

내가 PARAMS없이 호출 "시작"방법을 시도하는 경우 나는

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

+0

는'primaryStage' 제거, 널 수 없을 것'?'유형과 변수 메서드 호출에서. – Renato

답변

1

당신은

0,123 확산 연산자를 사용할 필요가 예외 다음 한
fun main(args: Array<String>) { 
    Application.launch(Starter::class.java, *args) 
} 
+0

감사합니다. 그것은 작동합니다. 또한 "기본"방법에 "컴패니언 개체"블록을 추가해야합니다. '동반자 개체 { @JvmStatic 재미 주 (인수 : 배열 ) { 출시 (스타터 :: class.java, * 인수) } 가}' –

+0

컴패니언 객체가 필요하지 않습니다를. 위와 같이하면 작동합니다. – Renato

+1

'main' 함수를 클래스 안에 두지 말고 그냥 두십시오. – Renato

관련 문제