javafx fxml file not found

package gioco.progettospacca.controller;

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) {
}
}
package gioco.progettospacca.controller;

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
16 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @asdru! 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.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot10mo ago
💤 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.
asdru
asdruOP10mo ago
i dont understand why main.java can find it but controller/homecontroller.java cant
No description
JavaBot
JavaBot10mo ago
💤 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.
💤 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.
asdru
asdruOP10mo ago
.
dan1st
dan1st10mo ago
you named the folder gioco.progettospacc... it should be a folder named guico with a folder progettospacc... in it
asdru
asdruOP10mo ago
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 /
dan1st
dan1st10mo ago
inside src/main/java, yes inside src/main/resources, no at least when I last used IntelliJ
asdru
asdruOP10mo ago
No description
dan1st
dan1st10mo ago
ok it needs to be in the controller package/directory
asdru
asdruOP10mo ago
ah so resources/gioco/progettospacca/controller?
dan1st
dan1st10mo ago
since you are using getClass().getResource("LoginAdminView.fxml") which requires it to be in the same directory yes or you change it to getClass().getClassLoader().getResource("gioco/progettospacca/controller/LoginAdminView.fxml")
asdru
asdruOP10mo ago
yes it works!! thank you so much
JavaBot
JavaBot10mo ago
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.
JavaBot
JavaBot10mo ago
Post Closed
This post has been closed by <@372715536121069578>.
Want results from more Discord servers?
Add your server