1

I am trying to make 3 folders in a Javafx application. I have a Views folder which will contain my views, and I want to load an fxml file saved inside Views. I wrote this code inside start method:

Parent root = FXMLLoader.load(getClass().getResource("/Views/ProductView.fxml"));

My folders are structured as follows: enter image description here

Apparently GetResources() can't find my file. What am I doing wrong?

Ayoub.A
  • 1,943
  • 3
  • 27
  • 34
  • 1
    I think the proble is that you have no `/View` but `/application/View` can you try that? However you may also try `View/` since your Main class is in the 'application' package – Clayn Nov 09 '16 at 15:11

2 Answers2

3

Problem is that loader cannot find fxml file ... So, load method can be either empty or gets Inputstream argument. And this should work:

FXMLLoader loader = new FXMLLoader();
FileInputStream fileInputStream = new FileInputStream(new File("src/main/java/CRUD/bnkseekCRUD.fxml"));
    Parent root = loader.load(fileInputStream);

At least it works for me. )))

Shamil
  • 51
  • 4
2

try something like this something like this Parent root=FXMLLoader.load(getClass().getClassloader().getResource("application/Models/Views/ProductView.fxml")

ground
  • 76
  • 1
  • 10