edvin / tornadofx

Lightweight JavaFX Framework for Kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

After build nothing is displayed on screen.

f4004 opened this issue · comments

commented

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.

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

commented

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

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?

commented

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

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

image

commented

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.

Have you got tornadofx imported using import tornadofx.*?

commented

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.

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

commented
  • 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.

  • 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.

commented

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.

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

Can you post the errors?

commented

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

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

commented

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.

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