我的JavaFx项目在Intellij IDEA中运行良好,但是当我使用命令行编译和运行它们时,出现了一些问题 错误如下: here is the screenshot of exception
这是我的主要课程:
@Override
public void start(Stage primaryStage) throws Exception{
FXMLLoader loader = new FXMLLoader(getClass().getResource("Ozlympic.fxml"));
//controller
loader.setController(new OzlympicController());
Parent root =loader.load();
primaryStage.setTitle("Ozlympic");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) throws IOException, selectOptionException {
//show the main stage, can not be commented
launch(args);
//get all athletes attend the game
ArrayList<Participates> participates=readTXTData.seperateData();
Driver driver = new Driver(participates);
//driver.mainMenu();
}
这是我的Ozlympic.fxml文件
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="750.0" prefWidth="974.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TabPane prefHeight="750.0" prefWidth="974.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab fx:id="swimTab" closable="false" text="Swim">
<fx:include source="Swim.fxml"/>
</Tab>
<Tab fx:id="runTab" closable="false" text="Run">
<fx:include source="Run.fxml"/>
</Tab>
<Tab fx:id="cycleTab" closable="false" text="Cycle">
<fx:include source="Cycle.fxml"/>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>
它说swim.fxml也存在一些问题 所以这是我的swim.fxml和控制器
<AnchorPane fx:id="swimPane" prefHeight="703.0" prefWidth="974.0" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="SwimController">
<Label alignment="CENTER" layoutX="528.0" layoutY="40.0" prefHeight="44.0" prefWidth="320.0"
text="Here is the results of swim game" textAlignment="CENTER">
<font>
<Font name="Arial Bold" size="19.0"/>
</font>
</Label>
<ListView fx:id="swimResult" layoutX="480.0" layoutY="107.0" prefHeight="477.0" prefWidth="439.0"/>
<Label layoutX="49.0" layoutY="51.0" text="Choose the Athlete attend the swim (4-8)">
<font>
<Font name="Arial Bold" size="19.0"/>
</font>
</Label>
<Group layoutX="-6.0" layoutY="110.0">
<CheckBox fx:id="athlete9" layoutX="265.0" layoutY="209.0" mnemonicParsing="false" prefHeight="18.0"
prefWidth="167.0" text="CheckBox"/>
.....
这是控制器:
public class SwimController implements Initializable{
@FXML public static CheckBox athlete1;
@FXML public static CheckBox athlete2;
@FXML public static CheckBox athlete3;
@FXML public static CheckBox athlete4;
@FXML public static CheckBox athlete5;
@FXML public static CheckBox athlete6;
@FXML public static CheckBox athlete7;
@FXML public static CheckBox athlete8;
@FXML public static CheckBox athlete9;
@FXML public static CheckBox athlete10;
@FXML public static CheckBox athlete11;
@FXML public static CheckBox athlete12;
@FXML public static Button btnExit;
@FXML public static Button btnSave;
@FXML public static Button btnStartGame;
@FXML public static ListView swimResult;
@FXML public AnchorPane swimPane;
@Override
public void initialize(URL location, ResourceBundle resources) {
}
@FXML private void btnExitAction(){
System.out.println("Exit button pressed!");
}
@FXML private void btnSaveAction(){
System.out.println("Save button pressed!");
}
@FXML private void btnStartGameAction(){
System.out.println("Start button pressed!");
}
@FXML public static Button generateAthlete;
@FXML private void btnGenerateAction(){
System.out.println("Generate button pressed!");
}
}
先谢谢你的帮助!