I have a package called app and within this I have two packages one called res and another graphics, within this last one I have a class with a method, which is responsible for creating an ImageView
private ImageView getImageViewFrom(String path){
return new ImageView(getClass().getResource(path).toString());
}
When I call it, I call it an argument "../res/image.png" to get the image, however, it throws a NullPointerException in the line of that method, and it did not understand, because, that is, the file exists in app / res / image.png and the class in app / graphics / GraphicLoader.java.
GraphicLoader Class
package app.graficos;
import app.modelo.Juego;
import javafx.scene.layout.GridPane;
import java.lang.UnsupportedOperationException;
public final class GraphicLoader{
private GraphicLoader(){
throw new UnsupportedOperationException();
}
public static GridPane createAndAddWithGraphics(Juego juego, GridPane gp){
for(int i=0; i<juego.getTablero().getFilas(); i++){
for(int j=0; j<juego.getTablero().getColumnas(); j++){
gp.add(getImageViewFrom("../res/0.PNG"));
}
}
return gp;
}
private static ImageView getImageViewFrom(String path){
return new ImageView(getClass().getResource(path).toString());
}
}