getResource() - >来源未找到 [英] getResource() -> Source not found

查看:162
本文介绍了getResource() - >来源未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照此处的教程进行操作。该文件位于项目的同一根文件夹中。我已经尝试过它在src文件夹和同一个包文件夹中。这3个地点都不起作用。

I'm following the tutorial here. The file is in the same root folder of the project. I've tried doing it when it's in the src folder and in the same package folder. None of those 3 locations worked.

具体的代码行是:

ImageIcon ii = new ImageIcon(this.getClass().getResource("bardejov.jpg"));

我知道我做错了吗?

推荐答案

// absolute from the classpath
MyClass.class.getResource("/myfolder/abc.txt");
// relative to the class location
MyClass.class.getResource("abc.txt");
// another relative to the class location
MyClass.class.getResource("myfolder/abc.txt");

这篇关于getResource() - >来源未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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