0

我正在开发一个 JavaFX 应用程序,在这个应用程序中,我从我的网络服务器加载了 fxml 文件,但我一直收到错误消息。我该如何解决这个错误?

FXML 来源: http: //fryslanscripts.net63.net/cache/Fighter/fighter.fxml

错误:

javafx.fxml.LoadException: 
/cache/Fighter/fighter.fxml

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2595)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2573)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2435)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2403)
at j.start(FighterFXUI.java:32)
at J.run(FighterFXUI.java:53)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$59/542475950.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$58/481059372.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(WinApplication.java)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$50/2063016732.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at D.initialize(FighterController.java:52)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2542)
... 14 more

我正在使用此代码启动应用程序:

import javafx.application.Application;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.IOException;
import java.net.URL;

public class FighterFXUI extends Application {

public static Stage stage;

@Override
public void start(final Stage stage) {
    try {
        LogUtil.append("Setting Stage.");
        this.stage = stage;
        LogUtil.append("Setting FXML Loader.");
        FXMLLoader loader = new FXMLLoader();
        LogUtil.append("Setting Controller.");
        loader.setController(new FighterController());
        LogUtil.append("Setting FXML File.");
        loader.setLocation(new URL("http://fryslanscripts.net63.net/cache/Fighter/fighter.fxml"));
        LogUtil.append("Loading Scene.");
        Parent page = (Parent) loader.load();
        Scene scene = new Scene(page);
        LogUtil.append("Setting Stylesheet.");
        scene.getStylesheets().add("http://fryslanscripts.net63.net/cache/Fighter/fighter.css");
        stage.setScene(scene);
        LogUtil.append("Showing Stage.");
        stage.initStyle(StageStyle.UNDECORATED);
        stage.show();
        Platform.setImplicitExit(false);

    } catch (IOException e) {
        LogUtil.append(LogUtil.getStackTrace(e));
        e.printStackTrace();
    }
}

public static void main() {
    LogUtil.append("Loading FX Toolkit.");
    new JFXPanel();

    LogUtil.append("Loading UI.");
    Platform.runLater(new Runnable() {
        public void run() {
            Platform.setImplicitExit(false);
            new FighterFXUI().start(new Stage());
        }
    });
}
}

这是 FighterController 类

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.input.KeyEvent;
import org.rev317.min.api.methods.Game;
import org.rev317.min.api.methods.Players;
import org.rev317.min.api.wrappers.Tile;

import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;


public class FighterController implements Initializable {

@FXML
TextField customNpcTextField, safespotTextField, specialAttackID, regularAttackID, foodIDTextField,
        minHealthTextField, customLootTextField, maxLootDistanceTextField, searchNpcTextField, searchItemTextField;

@FXML
Slider specialAttackPercentSlider;

@FXML
CheckBox burryBonesCheckBox, quickPrayersCheckBox, addCoinsToMoneyPouchCheckBox, eatToMakeSpaceForLootCheckBox,
        FoodLobsterCheckBox, FoodMonkfishCheckBox, FoodSharkCheckBox, FoodCaveFishCheckBox, FoodMantaRayCheckBox,
        FoodRockTailCheckBox;

@FXML
Button startButton, setSafeSpotButton, findMonsterByNameButton, addNpcButton, removeNpcButton,addLootButton,removeLootButton;

@FXML
TextArea updateLogTextArea;

@FXML
ListView cachedNpcsList, savedNpcsList,cachedItemsList,savedItemsList;

@Override
public void initialize(URL location, ResourceBundle resources) {

    startButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            try {
                LogUtil.append("Setting ArrayLists.");
                if (FryslanFighter.itemCache == null) {
                    FryslanFighter.itemCache = new ArrayList<>();
                }

                if (FryslanFighter.npcCache == null) {
                    FryslanFighter.npcCache = new ArrayList<>();
                }

                if( FryslanFighter.ids == null){
                    FryslanFighter.ids = new ArrayList<>();
                }

                if( FryslanFighter.loot == null){
                    FryslanFighter.loot = new ArrayList<>();
                }

                if( FryslanFighter.food == null){
                    FryslanFighter.food = new ArrayList<>();
                }

                //Add Npcs
                LogUtil.append("Adding NPC's.");
                String npcIds = customNpcTextField.getText().trim();
                if(!customNpcTextField.getText().isEmpty()) {
                    if(npcIds != null) {
                        for (String id : npcIds.split(",")) {
                            FryslanFighter.ids.add(Integer.parseInt(id));
                        }
                    }
                }

                ObservableList npcs = savedNpcsList.getItems();
                if(npcs.size() > 0){
                    for(Object npc : npcs){
                        FryslanFighter.ids.add(Integer.parseInt(npc.toString().split(" - ")[0]));
                    }
                }

                //Add Loot
                LogUtil.append("Adding Loot.");
                String lootIds = customLootTextField.getText().trim();
                if(!customLootTextField.getText().isEmpty()) {
                    for (String id : lootIds.split(",")) {
                        FryslanFighter.loot.add(Integer.parseInt(id) - 1);
                    }
                }

                ObservableList loots = savedItemsList.getItems();
                if(loots.size() > 0){
                    for(Object loot : loots){
                        FryslanFighter.loot.add(Integer.parseInt(loot.toString().split(" - ")[0]));
                    }
                }

                LogUtil.append("Adding Textfield data.");
                FryslanFighter.specialAttackWeaponId = Integer.parseInt(specialAttackID.getText());
                FryslanFighter.regularAttackWeaponId = Integer.parseInt(regularAttackID.getText());
                FryslanFighter.food.add(Integer.parseInt(foodIDTextField.getText()));
                FryslanFighter.minHP = Integer.parseInt(minHealthTextField.getText());
                FryslanFighter.distanceToLoot = Integer.parseInt(maxLootDistanceTextField.getText());
                FryslanFighter.specialAttackEnergy = (int) specialAttackPercentSlider.getValue();
                System.out.println((int) specialAttackPercentSlider.getValue());

                LogUtil.append("Adding CheckBox data.");
                FryslanFighter.burryBones = burryBonesCheckBox.isSelected();
                FryslanFighter.useQuickPrayers = quickPrayersCheckBox.isSelected();
                FryslanFighter.addCoinsToMoneyPouch = addCoinsToMoneyPouchCheckBox.isSelected();
                FryslanFighter.eatToMakeSpaceForLoot = eatToMakeSpaceForLootCheckBox.isSelected();

                if (FoodLobsterCheckBox.isSelected()) {
                    FryslanFighter.food.add(380);
                }

                if (FoodMonkfishCheckBox.isSelected()) {
                    FryslanFighter.food.add(7947);
                }

                if (FoodSharkCheckBox.isSelected()) {
                    FryslanFighter.food.add(386);
                }

                if (FoodCaveFishCheckBox.isSelected()) {
                    FryslanFighter.food.add(15267);
                }

                if (FoodMantaRayCheckBox.isSelected()) {
                    FryslanFighter.food.add(392);
                }

                if (FoodRockTailCheckBox.isSelected()) {
                    FryslanFighter.food.add(15273);
                }

                LogUtil.append("Handling UI Closing.");
                Platform.setImplicitExit(false);
                if(FighterFXUI.stage != null) {
                    FighterFXUI.stage.close();
                }
                LogUtil.append("Setting loaded variable to True.");
                FryslanFighter.loaded = true;
            } catch (NumberFormatException e) {
                LogUtil.append(LogUtil.getStackTrace(e) + "\n");
                e.printStackTrace();
            }

        }
    });
}

}

4

0 回答 0