tornadofx icon indicating copy to clipboard operation
tornadofx copied to clipboard

After build nothing is displayed on screen.

Open f4004 opened this issue 4 years ago • 17 comments

I fixed all of problems about gradle and building. But I still have a problem. Having clicked Run I get BUILD SUCCESSFUL but nothing appear. And program is ended by doing nothing. Why?

Build output:

BUILD SUCCESSFUL in 920ms
1 actionable task: 1 executed
Task execution finished.

f4004 avatar Feb 28 '21 15:02 f4004

Build what? Are you building the tornadofx library or your own project?

SKeeneCode avatar Mar 01 '21 13:03 SKeeneCode

I'm build my own project. I'm trying to use TornadoFX library in my project. I've tried this code.

f4004 avatar Mar 01 '21 13:03 f4004

Put a launch function outside:

Main.kt

class HelloWorld : View() {
    override val root = hbox {
        label("Hello world")
    }
}

class HelloWorldApp : App(HelloWorld::class, Styles::class)

class Styles : Stylesheet() {
    init {
        label {
            fontSize = 20.px
            fontWeight = FontWeight.BOLD
            backgroundColor += c("#cecece")
        }
    }
}

fun main() {
    launch<HelloWorldApp>()
}

and then in your gradle.build.kts:

application {
    mainClass.set("MainKt")
}

Then run using gradle. Does this work?

SKeeneCode avatar Mar 01 '21 14:03 SKeeneCode

Thanks for your answer. But it doesn't work anyway. Still same.

f4004 avatar Mar 01 '21 15:03 f4004

Are you sure you're running the run task? Gradle > Tasks > Application > run?

image

SKeeneCode avatar Mar 01 '21 15:03 SKeeneCode

I got new error this time when I tried your code:

src\main\kotlin\main.kt: (1, 20): Unresolved reference: View

When I tried the code I've wrote, I got this error:

src\main\kotlin\main.kt: (4, 27): Unresolved reference: HelloWorld

From Gradle > Run section.

f4004 avatar Mar 01 '21 15:03 f4004

Have you got tornadofx imported using import tornadofx.*?

SKeeneCode avatar Mar 01 '21 15:03 SKeeneCode

Yeah now it is working. Thank you. It needs to import javafx.scene.text.FontWeight. Thank you again. Can I some question regarding this codes.

f4004 avatar Mar 01 '21 16:03 f4004

No problem. Feel free to ask anything else - if I can answer I will :)

SKeeneCode avatar Mar 01 '21 16:03 SKeeneCode

  • What is the difference between Run from Intellij and Run from Gradle and why nothing is displayed when I clicked Run(from Intellij)?

  • Why we used mainClass ("MainKt") instead of mainClassName = "MainKt" in build.gradle.kts? Actually when I've tried both are works fine.

f4004 avatar Mar 01 '21 19:03 f4004

  • What is the difference between Run from Intellij and Run from Gradle and why nothing is displayed when I clicked Run(from Intellij)?

Are you sure you're actually running the application in intellij? By clicking the green arrow and not just the build button? image I'm guessing there is something mistaken with your set up.

I think I might need to look at your project to determine exactly what is going wrong.

You can read more about exactly what a gradle run task does here.

  • Why we used mainClass ("MainKt") instead of mainClassName = "MainKt" in build.gradle.kts? Actually when I've tried both are works fine.

mainClassName = "MainKt" is deprecated, the other way seems to be the appropriate way of doing it now.

SKeeneCode avatar Mar 01 '21 20:03 SKeeneCode

Are you sure you're actually running the application in intellij? By clicking the green arrow and not just the build button? image

As your seen following image, I was clicking green arrow nothing appears after build. Actually when I click Run from top menu appears two section there. kotlinandtornadofx (with Gradle icon) and MainKt (with Kotlin icon) file. When I clicked MainKt, it gives a lot of debug error, but kotlinandtornadofx file doesn't give error but doesn't run anything neither. image After first Run in Gradle, kotlinandtornadofx - run section has been added.

f4004 avatar Mar 01 '21 20:03 f4004

When I clicked MainKt, it gives a lot of debug error

Can you post the errors?

SKeeneCode avatar Mar 01 '21 20:03 SKeeneCode

I'm sorry to keep you waiting. I was deleted that configuration before but I've created a new project and I tried. MainKt works fine. But why my previous project had Gradle symbol? Seem like MainKt and kotlinandtornadofx is run by another compiler or something.

image

f4004 avatar Mar 01 '21 21:03 f4004

well, without the configuration window, it is difficult to understand which task you are launching, if you yourself did not specify the name, then perhaps you have a custom task

SchweinchenFuntik avatar Mar 03 '21 18:03 SchweinchenFuntik

well, without the configuration window, it is difficult to understand which task you are launching

In fact, I wonder, there is only one task to run: it is project. Perhaps I don't know tasks.

f4004 avatar Mar 05 '21 05:03 f4004

terminal (linux): ./gradlew run (wrapper) or gradle run

SchweinchenFuntik avatar Mar 08 '21 14:03 SchweinchenFuntik