#javafx fxml file not found

27 messages · Page 1 of 1 (latest)

vivid pike
#

import gioco.progettospacca.classi.Partita;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

import java.io.IOException;

public class HomeController {
    @FXML
    public void giocaPartita(ActionEvent actionEvent) {

    }

    public void EventoCreaPartita(ActionEvent actionEvent) throws IOException{
        Parent root = FXMLLoader.load(getClass().getResource("LoginAdminView.fxml"));
        Scene scene=new Scene(root);
        Stage stage = (Stage)((Node)actionEvent.getSource()).getScene().getWindow();
        stage.setTitle("Login amministratore");
        stage.setScene(scene);
        stage.show();

    }

    public void giocaTorneo(ActionEvent actionEvent) {
    }

    public void creaTorneo(ActionEvent actionEvent) {
    }
}```
i get an error saying that
       `getClass().getResource("LoginAdminView.fxml") `at line 22 is null
i dont understand why since i have the same setup in the main class and that works. the only difference is that this class is in a subfolder and the main isnt. But i can't figure out what's wrong
eternal sailBOT
#

This post has been reserved for your question.

Hey @vivid pike! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

lament flicker
#

Can I see your project explorer and where you put your LoginAdminView.fxml file?

#

It should be in the root of your resources folder

eternal sailBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

vivid pike
#

i dont understand why main.java can find it but controller/homecontroller.java cant

eternal sailBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

eternal sailBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

vivid pike
#

.

long prairie
#

you named the folder gioco.progettospacc...

#

it should be a folder named guico with a folder progettospacc... in it

vivid pike
#

Are you sure? Cause the file is found if i put the getResource in the main

#

Oh wait they already are 2 folders

#

intellij just uses a . instad of the /

long prairie
#

inside src/main/resources, no

#

at least when I last used IntelliJ

vivid pike
long prairie
#

ok

long prairie
# vivid pike

it needs to be in the controller package/directory

vivid pike
#

ah so resources/gioco/progettospacca/controller?

long prairie
long prairie
#

or you change it to getClass().getClassLoader().getResource("gioco/progettospacca/controller/LoginAdminView.fxml")

vivid pike
#

yes it works!!
thank you so much

eternal sailBOT
# vivid pike yes it works!! thank you so much

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.