Kotlin. Basic JavaFX application
class MyApplication : Application() {
override fun start(primaryStage: Stage) {
}
}
fun main(args: Array<String>) {
Application.launch(MyApplication::class.java, *args)
}
The code samples you provided are not equivalent: an object
declaration in Kotlin is a singleton, so it only has one instance constructed by calling the private constructor when the class is initialized. JavaFX is trying to call the constructor of the class reflectively but fails because the constructor is private as it should be.
What you may be looking instead is a simple class declaration, with the main
in its companion object. If no explicit constructors are declared, Kotlin, like Java, will generate a default one, allowing JavaFX to instantiate the application:
class Test : Application() {
override fun start(stage: Stage) {
...
}
companion object {
@JvmStatic
fun main(args: Array<String>) {
launch(Test::class.java)
}
}
}
Here is simple method to perform launch of Java FX Application
class MyApplication: Application(){
override fun start(primaryStage: Stage?){
//You code here
}
companion object{
@JvmStatic
fun main(args: Array<String>){
launch(MyApplication::class.java, *args)
}
}
}