我的代码根本无法运行。以前,它找不到.fxml文件。清洗溶液后,我得到了这个错误。我相信主要的问题就在这里。我已将完整错误上传到pastebin中。我的FXML与其他.java文件一起在src下]
Caused by: java.lang.RuntimeException: Exception in Application start method at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900) at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195) at java.base/java.lang.Thread.run(Thread.java:832)
原因:javafx.fxml.LoadException:/C:/Users/jinyi/Desktop/CIS%2022C/CoronavirusUpdate/bin/fxml.fxml
at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2603) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136) at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113) at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106) at CoronavirusUpdateMain.start(CoronavirusUpdateMain.java:12) at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428) at java.base/java.security.AccessController.doPrivileged(AccessController.java:391) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427) at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96) at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174) ... 1 more
我的主
public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("fxml.fxml")); Scene scene = new Scene(root); stage.setScene(scene); stage.setResizable(false); stage.setMaxWidth(596); stage.setMaxHeight(280); stage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); }
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="280.0" prefWidth="596.0" style="-fx-background-color: #fff;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mainController">
<children>
<GridPane layoutX="133.0" layoutY="70.0" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="163.0" prefWidth="358.0" style="-fx-background-color: E8EAF6;" AnchorPane.bottomAnchor="47.0" AnchorPane.leftAnchor="133.0" AnchorPane.rightAnchor="105.0" AnchorPane.topAnchor="70.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="45.0" minHeight="10.0" prefHeight="45.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="55.0" minHeight="10.0" prefHeight="37.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #303F9F;" text="Select Country :" textFill="WHITE">
<font>
<Font name="Arial Bold" size="14.0" />
</font>
<GridPane.margin>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</GridPane.margin>
</Label>
<ComboBox fx:id="comboBox" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onAction="#getData" promptText="Countries" style="-fx-background-color: #E8EAF6;" GridPane.columnIndex="1">
<GridPane.margin>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</GridPane.margin>
</ComboBox>
<Label alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="41.0" prefWidth="122.0" style="-fx-background-color: #C5CAE9;" text="Cases :" GridPane.rowIndex="1">
<font>
<Font name="Arial Bold" size="14.0" />
</font>
<GridPane.margin>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</GridPane.margin>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #C5CAE9;" text="Deaths :" GridPane.rowIndex="2">
<font>
<Font name="Arial Bold" size="14.0" />
</font>
<GridPane.margin>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</GridPane.margin>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #C5CAE9;" text="Population:" GridPane.rowIndex="3">
<font>
<Font name="Arial Bold" size="14.0" />
</font>
<GridPane.margin>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</GridPane.margin>
</Label>
<Label fx:id="lcases" alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #C5CAE9;" GridPane.columnIndex="1" GridPane.rowIndex="1">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
<GridPane.margin>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</GridPane.margin>
<graphic>
<Label fx:id="ldeaths1" alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #C5CAE9;">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
<graphic>
<Label fx:id="totalCases" alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #C5CAE9;">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
</Label>
</graphic>
</Label>
</graphic>
</Label>
<Label fx:id="totalDeaths" alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #C5CAE9;" GridPane.columnIndex="1" GridPane.rowIndex="2">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
<GridPane.margin>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</GridPane.margin>
</Label>
<Label fx:id="pop" alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #C5CAE9;" GridPane.columnIndex="1" GridPane.rowIndex="3">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
<GridPane.margin>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</GridPane.margin>
</Label>
<Label fx:id="worldPop" alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #C5CAE9;" GridPane.columnIndex="2" GridPane.rowIndex="3">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
</Label>
<Label fx:id="worldTotalDeaths" alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #C5CAE9;" GridPane.columnIndex="2" GridPane.rowIndex="2">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
</Label>
<Label fx:id="worldTotalCase" alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="25.0" prefWidth="111.0" style="-fx-background-color: #C5CAE9;" GridPane.columnIndex="2" GridPane.rowIndex="1">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
</Label>
</children>
</GridPane>
<Label alignment="CENTER" layoutX="62.0" layoutY="14.0" prefHeight="41.0" prefWidth="458.0" style="-fx-background-color: #3F51B5;" text="Countries where COVID-19 has spread" textFill="WHITE">
<font>
<Font name="Aparajita Bold" size="27.0" />
</font>
</Label>
</children>
</AnchorPane>
我的代码根本无法运行。以前,它找不到.fxml文件。清洗溶液后,我得到了这个错误。我相信主要的问题就在这里。我已将完整错误上传到pastebin中。我的...
更新的Chrome版本工作正常,感谢@Andreas