getClass()。getResource()始终返回null [英] getClass().getResource() always returning null

查看:542
本文介绍了getClass()。getResource()始终返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置我的src文件夹中资源文件夹中的图像的URL。它始终将URL设置为null。图像在那里,一切都被正确命名。有什么问题?谢谢!

I am trying to set the URL of an image that is located in my resource folder in my src folder. It is always setting the URL to null. The image is there and everything is named correctly. What is the issue? Thanks!

我的文件结构:


  • sp1

    • src

      • 资源

        • 01.png

        这是我的代码,我想设置图片的URL:

        Here is my code where i am trying to set the URL for the picture:

        this.setImagePath(getClass().getResource("/resources/01.png"));
        






        而且setImagePath正在做这件事,我相信这不是问题,因为我遵循执行,它正在设置为null。


        And the setImagePath is doing this, i am sure this is not the problem, because i followed the execution and it is setting it equal to null.

        public final void setImagePath(URL imagePath) {
            this.imagePath = imagePath;
        }
        






        解决方案

        我不得不清理构建并重建。

        I had to clean the build and rebuild. It worked after that fix.

        谢谢

        推荐答案

        我不得不清理构建然后重建。现在工作。

        I had to clean the build and then rebuild. Works now.

        这篇关于getClass()。getResource()始终返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆