我需要在我的cisc课程中为这个考试工作,但java和我似乎没有很长时间。我一直在启动时遇到这些错误,我到处寻找答案,但是没有得到它。谁能告诉我我做错了什么......?
这些是主要方法和我试图链接到它的fxml。目前没有太多任何东西,因为我只是想让它运行。
package main;
import java.io.IOException;
import calculator.view.calcController;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class Main extends Application {
private Stage primaryStage;
private AnchorPane Layout;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("Calculator");
this.primaryStage.getIcons().add(new Image("file: C://Users/Amanda/Documents/1427173308_Address_Book.png"));
initRootLayout();
}
/**
* Initializes the root layout.
*/
@FXML
public void initRootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(main.Main.class.getResource("view/Layout.fxml"));
Layout = (AnchorPane) loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(Layout);
primaryStage.setScene(scene);
// Give the controller access to the main app.
calcController controller = loader.getController();
controller.setMain(this);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
这是我得到的错误。我已经尝试将位置更改为我能想象到的所有内容,但它无法正常工作。
Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow`enter code here`n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$48/1108411398.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at main.Main.initRootLayout(Main.java:39)
at main.Main.start(Main.java:26)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/1905880089.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/1184208461.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)
... 1 more