我希望有人可以帮我解决问题。
问题是当我启动程序时,我总是得到一个异常,说找不到源文件。我已经使用互联网通过使用异常消息作为谷歌的搜索参数来解决问题。但我找不到解决方案。
异常消息:
java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at com.kw.overtaker_monitoring.Main.start(Main.java:18)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/924394080.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/1051754451.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/389777815.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
SceneBuilder中的错误消息:
在FXML控制器类中找不到id'btnSelectDatabaseFile'
的可注入字段有关详细信息,我将为您提供以下课程的代码
Main.java(主类):
package com.kw.overtaker_monitoring;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application
{
@Override
public void start(Stage primaryStage)
{
try
{
Parent root = FXMLLoader.load(getClass().getResource("MainWindow.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
launch(args);
}
}
MainWindow.fxml(GUI文件):
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="561.0" prefWidth="830.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kw.IO.Controller">
<children>
<Accordion layoutX="22.0" layoutY="68.0" prefHeight="18.0" prefWidth="7.0" />
<Accordion layoutX="14.0" layoutY="14.0" prefHeight="639.0" prefWidth="889.0" AnchorPane.bottomAnchor="16.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0">
<panes>
<TitledPane animated="false" text="First">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="187.0" prefWidth="234.0">
<children>
<Button id="btnAddSizeToFolderName" fx:id="btnAddSizeToFolderName" layoutX="142.0" layoutY="84.0" mnemonicParsing="false" onAction="#RunFolderRenaming" text="Add size to foldername" />
<TextField id="txtSrcPath" fx:id="txtSrcPath" layoutX="112.0" layoutY="14.0" prefHeight="25.0" prefWidth="671.0" />
<Label layoutX="22.0" layoutY="18.0" text="sourcepath" />
<Label layoutX="22.0" layoutY="48.0" text="destinationpath" />
<TextField id="txtDestPath" fx:id="txtDestPath" layoutX="112.0" layoutY="44.0" prefHeight="25.0" prefWidth="672.0" />
<CheckBox fx:id="chkIncludeSubDirs" layoutX="22.0" layoutY="88.0" mnemonicParsing="false" text="Only subdirs" />
<Separator layoutX="-5.0" layoutY="75.0" prefHeight="3.0" prefWidth="808.0" />
<Separator layoutX="-4.0" layoutY="116.0" prefHeight="3.0" prefWidth="808.0" />
<TextField id="txtSrcPath" fx:id="txtOldFileName" layoutX="14.0" layoutY="126.0" prefHeight="25.0" prefWidth="176.0" />
<TextField id="txtSrcPath" fx:id="txtReplaceWith" layoutX="282.0" layoutY="126.0" prefHeight="25.0" prefWidth="176.0" />
<Label layoutX="212.0" layoutY="130.0" text="replace with" />
<Button id="btnAddSizeToFolderName" fx:id="btnReplace" layoutX="469.0" layoutY="126.0" mnemonicParsing="false" onAction="#RunFileRenaming" text="replace from all files in folder" />
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="Movie Database Tools">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextField editable="false" layoutX="141.0" layoutY="10.0" prefHeight="25.0" prefWidth="651.0" />
<Button layoutX="14.0" layoutY="10.0" mnemonicParsing="false" onMouseClicked="#btnSelectDatabaseFile_Clicked" text="Select Database File" />
</children></AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="untitled 3">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="434.0" prefWidth="731.0" />
</content>
</TitledPane>
</panes>
</Accordion>
</children>
</AnchorPane>
Controller.java(控制器类):
package kw.IO;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
public class Controller implements Initializable
{
@FXML
private Button btnAddSizeToFolderName;
@FXML
private Button btnReplace;
@FXML
private Button btnSelectDatabaseFile;
@FXML
private TextField txtSrcPath;
@FXML
private TextField txtOldFileName;//TODO: übergeben
@FXML
private TextField txtReplaceWith;//TODO: übergeben
@FXML
private CheckBox chkIncludeSubDirs;
private Operator operator = new Operator();
@Override
public void initialize(URL location, ResourceBundle resources)
{
// TODO Auto-generated method stub
}
// this starts the a thread with the function of renaming folders by adding their size to them
public void RunFolderRenaming(ActionEvent event)
{
System.out.println("Button wurde geklickt!");
System.out.println(txtSrcPath.getText());
operator.StartFolderRenaming(txtSrcPath.getText().toString(), chkIncludeSubDirs.isSelected());
}
public void RunFileRenaming(ActionEvent event)
{
System.out.println("File renaming button clicked!");
operator.ReplaceFromFiles(txtSrcPath.getText(), txtOldFileName.getText(), txtReplaceWith.getText());
}
public void btnSelectDatabaseFile(ActionEvent btnSelectDatabaseFile_Clicked)
{
System.out.println("Button Select Database File was clicked!");
}
}
请帮我解决我的问题?
亲切的问候
骄傲