I have an FXML file that is in a separate package. this answer is close but it is located in the same package.
the what confuses me is
- Where is this path /src/resources/.fxml that some of the answers reference
How do I "copy" my fxml code into it. This is the line of code that is getting me Nullpointerexception: Location is Required
root = FXMLLoader.load(getClass().getResource("IMSView/AppView.fxml"));
I have tried it with
root = FXMLLoader.load(getClass().getResource("/IMSView/AppView.fxml"));
Still get the same failure.
I am very new to java and I know I am doing something wrong. I could get this project to run when everything was in one file path. Now that I have added packages I cannot get the fxml to load.
Thanks for your time.
EDIT
I am using netbeans The Main method ins in IMS.java The FXML that I want to load is in a package called IMSview and is name AppView.fxml Project files
My Code
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ims;
import IMSModel.Product;
import IMSModel.Part;
import IMSView.AddProductController;
import IMSView.AppViewController;
import IMSView.AddPartController;
import java.io.IOException;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
/**
*
* @author DBarnett
*/
public class IMS extends Application {
private Stage primaryStage;
private Stage window;
private BorderPane rootLayout;
private ObservableList<Part> PartData = FXCollections.observableArrayList();
private ObservableList<Product> ProductData = FXCollections.observableArrayList();
public IMS() {
// Add some sample data
// PartData.add(new InHouse(1,"Silly Cow",1,23));
// ProductData.add(new OutSourced(2"dog",2,3));
}
/**
* Returns the data as an observable list of Parts.
*
* @return
*/
public ObservableList<Part> getPartData() {
return PartData;
}
public ObservableList<Product> getProductData() {
return ProductData;
}
@Override
public void start(Stage primaryStage) throws IOException {
window = primaryStage;
Parent root;
root = FXMLLoader.load(getClass().getResource("IMSView/AppView.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("IMS");
primaryStage.setScene(scene);
primaryStage.show();
// this.primaryStage = primaryStage;
// this.primaryStage.setTitle("Inventory Management System");
window.setOnCloseRequest(e -> {
e.consume();
closeProgram();
});