我有几个带有相应控制文件的fxml文件。除了一个以外,它们都起作用。那个曾经工作。这是错误日志。
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.mycompany.kioskapp2.App.loadFXML(App.java:34)
at com.mycompany.kioskapp2.App.setRoot(App.java:29)
at com.mycompany.kioskapp2.PrimaryController.BrowseItemsButtonAction(PrimaryController.java:24)
App.java
public class App extends Application {
private static Scene scene;
public static String Username, Password;
@Override
public void start(Stage stage) throws IOException {
scene = new Scene(loadFXML("primary"), 800, 700);
stage.setTitle("Grogan Vending");
stage.setScene(scene);
stage.show();
}
static void setRoot(String fxml) throws IOException {
System.out.println("in setRoot");
scene.setRoot(loadFXML(fxml));
}
private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
return fxmlLoader.load();
}
@SuppressWarnings("empty-statement")
public static void VerifyUsername(String user, String passwd) throws IOException {
System.out.println("in App.VerifyUsername");
Boolean bool1 = false;
Boolean bool2 = false;
Boolean found1 = false;
Boolean found2 = false;
String savestr = null;
try {
try (FileReader reader = new FileReader("C:\\Users\\Skibum.DESKTOP-DBDQH1D\\Documents\\NetBeansProjects\\KioskApp2\\src\\main\\resources\\com\\mycompany\\kioskapp2\\LoginFile.txt")) {
BufferedReader bufferedReader = new BufferedReader(reader);
String dbline;
while ((dbline = bufferedReader.readLine()) != null) {
bool1 = dbline.contains(user);
if (bool1 == true) {
found1 = true;
found2 = dbline.contains(passwd);
savestr = dbline;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
if (found2 == false) {
App.setRoot("passwderr");
}
if (found1 == false) {
try {
App.setRoot("usernameerr");
} catch (IOException ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (found1 == true && found2 == true) {
String result[] = savestr.split(",");
for (String temp: result){
}
System.out.println(result[2]);
App.setRoot("primary");
}
}
public static void main(String[] args) {
launch(args);
}
}
PrimaryController.java
public class PrimaryController {
@FXML private Text actiontarget;
@FXML private void LoginButtonAction() throws IOException {
App.setRoot("login");
System.out.println("Login button pressed");
}
@FXML private void NewAccountButtonAction() throws IOException {
App.setRoot("newaccount");
System.out.println("New Account button pressed");
}
@FXML private void BrowseItemsButtonAction() throws IOException {
App.setRoot("browse");
System.out.println("Browse Items button pressed");
}
@FXML private void ExpenseAcctButtonAction()throws IOException {
App.setRoot("expenseacct");
System.out.println("expense acct button pressed");
}
@FXML private void HelpButtonAction()throws IOException {
App.setRoot("help");
System.out.println("Help button pressed");
}
@FXML private void SuggestButtonAction()throws IOException {
App.setRoot("suggestions");
System.out.println("Suggestions button pressed");
}
}
您缺少事件类型是函数的参数
BrowseItemsButtonAction()
应该是
BrowseItemsButtonAction(MouseEvent event)