0

So i have an FXML project with a few stuff in it, and to test out a function in the UI i'm making i decided to create a 2nd main function named Main2 that loads up an FXML named HomePage (controller code at the bottom). so here's main2 first

package javafxapplication4;

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main2 extends Application  {
    
    @Override
    public void start(Stage primaryStage) {
        try {
            
            Parent root = FXMLLoader.load(getClass().getResource("HomePage.fxml"));
            Scene scene = new Scene(root,750,500);
            primaryStage.setScene(scene);
            primaryStage.show();
            primaryStage.setResizable(false);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        launch(args);   
    }
}

and here is HomePage controller

package javafxapplication4;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.layout.AnchorPane;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.animation.FadeTransition;

import javafx.scene.Node;
import javafx.util.Duration;

public class HomePageController implements Initializable {

    @FXML AnchorPane holderPane;
   
    AnchorPane home;
    
    
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        createPage();
        
    }    
        private void setNode(Node node){
            holderPane.getChildren().clear();
            holderPane.getChildren().add((Node)node);
            
            FadeTransition ft = new FadeTransition(Duration.millis(1500));
            ft.setNode(node);
            ft.setFromValue(0.1);
            ft.setToValue(1);
            ft.setCycleCount(1);
            ft.setAutoReverse(false);
            ft.play();
            
        }
    private void createPage() {
        try {
            home = FXMLLoader.load(getClass().getResource("HOME.fxml"));
            setNode(home);
        } catch (IOException e) {
            e.printStackTrace();
            }
        
    
    }
    
}

HOME.fxml is another FXML file that's supposed to load up on an anchor pane that's inside HomePage HOME.fxml has an empty controller btw

package javafxapplication4;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.Initializable;

public class HOMEController implements Initializable {

    @Override
    public void initialize(URL url, ResourceBundle rb) {


    }    
    
}

now for some reason i'm getting an error when i try to run the Main2 File on it's own and honestly i'm kind of stuck and wondering if someone can be able to help me fix this error enter image description here

Here's the FXML for HomePage

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>

<AnchorPane id="AnchorPane" prefHeight="500.0" prefWidth="750.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication4.HomePageController">
   <children>
      <Separator layoutX="147.0" layoutY="8.0" orientation="VERTICAL" prefHeight="498.0" prefWidth="0.0" />
      <Separator layoutX="147.0" layoutY="37.0" prefHeight="1.0" prefWidth="600.0" />
      <Pane layoutY="-2.0" prefHeight="507.0" prefWidth="147.0" style="-fx-background-color: #36394B;">
         <children>
            <ImageView fitHeight="57.0" fitWidth="62.0" layoutX="45.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@Resources/cashier-pngrepo-com.png" />
               </image>
            </ImageView>
            <Label layoutY="71.0" prefHeight="57.0" prefWidth="147.0" text="Welcome to the Register" textFill="#bcb5b5" underline="true" />
            <Label layoutX="14.0" layoutY="145.0" prefHeight="57.0" prefWidth="147.0" text="Dashboard" textFill="#d3d3d3">
               <font>
                  <Font name="System Bold" size="22.0" />
               </font>
            </Label>
            <Label layoutX="3.0" layoutY="128.0" prefHeight="17.0" prefWidth="147.0" text="~~~~~~~~~~~~~~~~~" textFill="WHITE" />
            <JFXButton layoutX="14.0" layoutY="207.0" prefHeight="41.0" prefWidth="119.0" text="Products" textFill="#d3d0d0">
               <font>
                  <Font name="System Bold" size="20.0" />
               </font>
            </JFXButton>
            <JFXButton layoutX="14.0" layoutY="251.0" prefHeight="42.0" prefWidth="127.0" text="Add Products" textFill="#d3d0d0">
               <font>
                  <Font name="System Bold" size="16.0" />
               </font>
            </JFXButton>
            <JFXButton layoutX="14.0" layoutY="301.0" prefHeight="41.0" prefWidth="119.0" text="History" textFill="#d3d0d0">
               <font>
                  <Font name="System Bold" size="20.0" />
               </font>
            </JFXButton>
            <Label layoutX="4.0" layoutY="389.0" prefHeight="17.0" prefWidth="147.0" text="~~~~~~~~~~~~~~~~~" textFill="WHITE" />
            <JFXButton layoutX="11.0" layoutY="416.0" prefHeight="42.0" prefWidth="127.0" style="-fx-border-color: WHITE;" text="CONTACT US" textFill="#d3cdcd">
               <font>
                  <Font name="System Bold" size="16.0" />
               </font>
            </JFXButton>
            <Label layoutX="119.0" layoutY="221.0" prefHeight="17.0" prefWidth="16.0" style="-fx-background-color: #00dbff;" text="0" textAlignment="CENTER" textFill="WHITE">
               <font>
                  <Font name="System Bold" size="13.0" />
               </font>
            </Label>
         </children>
      </Pane>
      <Label contentDisplay="GRAPHIC_ONLY" layoutX="709.0" layoutY="8.0" prefHeight="30.0" prefWidth="41.0">
         <graphic>
            <ImageView fitHeight="30.0" fitWidth="29.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@Resources/menu.png" />
               </image>
            </ImageView>
         </graphic>
      </Label>
      <AnchorPane fx:id="holderPane" layoutX="147.0" layoutY="40.0" prefHeight="464.0" prefWidth="600.0">
         <children>
            <AnchorPane prefHeight="444.0" prefWidth="593.0">
               <children>
                  <Pane layoutX="34.0" prefHeight="200.0" prefWidth="200.0" />
                  <Pane layoutX="327.0" layoutY="222.0" prefHeight="200.0" prefWidth="200.0" />
                  <Pane layoutX="34.0" layoutY="222.0" prefHeight="200.0" prefWidth="200.0" />
                  <Pane layoutX="327.0" prefHeight="200.0" prefWidth="200.0" />
               </children>
            </AnchorPane>
         </children>
      </AnchorPane>
      <Label layoutX="351.0" layoutY="2.0" prefHeight="30.0" prefWidth="157.0" text="WELCOME">
         <font>
            <Font name="System Bold" size="29.0" />
         </font>
      </Label>
   </children>
</AnchorPane>

and HOME's FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>


<AnchorPane id="AnchorPane" prefHeight="444.0" prefWidth="593.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171" fx:controller="javafxapplication4.HOMEController">
   <children>
      <JFXButton alignment="BOTTOM_CENTER" contentDisplay="TOP" layoutX="70.0" layoutY="41.0" prefHeight="137.0" prefWidth="192.0" style="-fx-background-color: #36394B;" text="Meat" textFill="#eeeeee">
         <graphic>
            <ImageView fitHeight="100.0" fitWidth="117.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@Resources/kisspng-sausage-beefsteak-ribs-rib-eye-steak-cooked-meat-5a79790a9a1f69.8269101615179102826313.png" />
               </image>
            </ImageView>
         </graphic>
         <font>
            <Font name="System Bold" size="15.0" />
         </font>
      </JFXButton>
      <JFXButton alignment="BOTTOM_CENTER" contentDisplay="TOP" layoutX="341.0" layoutY="41.0" prefHeight="140.0" prefWidth="192.0" style="-fx-background-color: #36394B;" text="Sea food" textFill="WHITE">
         <graphic>
            <ImageView fitHeight="105.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@Resources/kisspng-seafood-lobster-crab-boston-lobster-meal-5a7c6edbb6d749.9654965815181042837489.png" />
               </image>
            </ImageView>
         </graphic>
         <font>
            <Font name="System Bold" size="15.0" />
         </font>
      </JFXButton>
      <JFXButton alignment="BOTTOM_CENTER" contentDisplay="TOP" layoutX="70.0" layoutY="222.0" prefHeight="137.0" prefWidth="192.0" style="-fx-background-color: #36394B;" text="Bakery" textFill="WHITE">
         <graphic>
            <ImageView fitHeight="106.0" fitWidth="131.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@Resources/kisspng-croissant-coffee-danish-pastry-milk-pain-au-chocol-a-pile-of-croissants-5a807d9ad35bb2.7678630115183702028657.png" />
               </image>
            </ImageView>
         </graphic>
         <font>
            <Font name="System Bold" size="15.0" />
         </font>
      </JFXButton>
      <JFXButton alignment="BOTTOM_CENTER" contentDisplay="TOP" layoutX="341.0" layoutY="223.0" prefHeight="140.0" prefWidth="192.0" style="-fx-background-color: #36394B;" text="Herbs" textFill="WHITE">
         <graphic>
            <ImageView fitHeight="132.0" fitWidth="144.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@Resources/kisspng-tea-herb-greek-cuisine-health-spice-herbs-png-photo-5a74a9173ea726.1607035815175949032566.png" />
               </image>
            </ImageView>
         </graphic>
         <font>
            <Font name="System Bold" size="15.0" />
         </font>
      </JFXButton>
   </children>
</AnchorPane>

0 Answers0