当我运行Application.kt时,出现此错误:
class Application :App(){
override val primaryView=Calculator::class
override fun start(stage: Stage) {
importStylesheet("/styleCSS.css")
stage.isResizable=false
super.start(stage)
}
我收到此错误
Fxml代码:
<?xml version="1.0" encoding="UTF-8"?>
<?override val root : BorderPane by fxml("/Application.fxml")?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<VBox id="calculator"
xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml">
<Label fx:id="display" id="display"/>
<HBox>
<Button text="C"/>
<Button text="+/-"/>
<Button text="\%"/>
<Button text="/" styleclass="op"/>
</HBox>
<HBox>
<Button text="7"/>
<Button text="8"/>
<Button text="9"/>
<Button text="X" styleclass="op"/>
</HBox>
<HBox>
<Button text="4"/>
<Button text="5"/>
<Button text="6"/>
<Button text="-" styleclass="op"/>
</HBox>
<HBox>
<Button text="1"/>
<Button text="2"/>
<Button text="3"/>
<Button text="+" styleclass="op"/>
</HBox>
<HBox>
<Button text="0" styleclass="zero"/>
<Button text="="/>
</HBox>
</VBox>
如果有帮助,这里是完整的堆栈跟踪记录:
java.lang.IllegalStateException: component.javaClass.getResource(resource) must not be null
at tornadofx.ResourceLookup.url(Component.kt:1304)
at tornadofx.FX$Companion$fxmlLocator$1.invoke(FX.kt:114)
at tornadofx.FX$Companion$fxmlLocator$1.invoke(FX.kt:88)
at tornadofx.UIComponent.loadFXML(Component.kt:1119)
at tornadofx.UIComponent$fxml$1.<init>(Component.kt:1113)
at tornadofx.UIComponent.fxml(Component.kt:1112)
at tornadofx.UIComponent.fxml$default(Component.kt:1112)
at Calculator.<init>(Calculator.kt:5)
at sun.reflect.NativeConstructoraccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructoraccessorImpl.newInstance(NativeConstructoraccessorImpl.java:62)
at sun.reflect.DelegatingConstructoraccessorImpl.newInstance(DelegatingConstructoraccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at tornadofx.FXKt.find(FX.kt:434)
at tornadofx.FXKt.find$default(FX.kt:423)
at tornadofx.App.start(App.kt:83)
at Application.start(Application.kt:14)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.accessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$3(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
我试图在我的fxml中给出这个“ <?override val root : BorderPane by fxml("/Application.fxml")?>
”,但是它不起作用,我是否需要在“ kotlin / main”上使用Component.kt?
谢谢您能给我的帮助。