JavaFX无效URL或未找到资源

JavaFX无效URL或未找到资源,java,image,gradle,javafx,Java,Image,Gradle,Javafx,我在JavaFX项目中包含图像时遇到了一些问题。该项目将资源存储在src/main/resources文件夹中,其中包含FXML文档和所有图像。FXML文档加载正常,但图像位置都显示为空 我的代码如下 package VennDiagram; import java.io.File; import javax.imageio.ImageIO; import javafx.application.Application; import javafx.fxml.FXMLLoader; impor

我在JavaFX项目中包含图像时遇到了一些问题。该项目将资源存储在src/main/resources文件夹中,其中包含FXML文档和所有图像。FXML文档加载正常,但图像位置都显示为空

我的代码如下

package VennDiagram;


import java.io.File;
import javax.imageio.ImageIO;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;

public class View extends Application{
    public static Stage primaryStage;
    public static Scene promptWindow;
    public static Scene refactor;
    public static Scene scene;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception{

        System.out.println(getClass().getResource("/views/View.fxml"));
        System.out.println(getClass().getResource("/views/openingPage.fxml"));
        System.out.println(getClass().getClassLoader().getResource("/views/openingPage.css"));
        primaryStage = stage;
        System.out.println(getClass().getResourceAsStream("/views/newFileButton.png"));
        Parent root = FXMLLoader.load(getClass().getResource("/views/View.fxml"));
        Parent root2 = FXMLLoader.load(getClass().getResource("/views/openingPage.fxml"));

        scene = new Scene(root);
        promptWindow = new Scene(root2,1020,580);
        primaryStage.setOnCloseRequest(event ->{
            quitProgramAlert.display("Confirm Exit", "Are you sure you want to exit?");
            if(!quitProgramAlert.closePressed) {
                event.consume();
            }       
        });

        primaryStage.setMinHeight(600);
        primaryStage.setMinWidth(750);
        primaryStage.setTitle("VennDiagram Creator");
        primaryStage.setScene(promptWindow);
        primaryStage.setResizable(false);
        primaryStage.show();
    }
}
它给我一个错误,说找不到资源

其他详情: 该项目是使用gradle构建的。我使用与图像相同的方法加载FXML文件。 它可以很好地处理FXML文档

编辑:项目结构如下所示。。。

发布项目结构。尝试使用
视图
而不是
/views
。如果它不能像建议的那样在项目后文件夹结构中工作。@c0der-我试过这个,它似乎不能工作。我更新了问题,将项目结构包括在内。谢谢您的帮助。@c如果FXML文件都能正常工作,我就能正确地看到它们。这只是我遇到问题的图像和css文件。你能显示使用PNG的fxml文件之一的代码吗?发布你的项目结构。尝试
视图
而不是
/views
。如果它不能像建议的那样在项目后文件夹结构中工作。@c0der-我试过这个,它似乎不能工作。我更新了问题,将项目结构包括在内。谢谢您的帮助。@c如果FXML文件都能正常工作,我就能正确地看到它们。这只是图像和css文件我有麻烦,你能显示其中一个fxml文件的代码,其中PNG正在使用吗?