【问题标题】:getClass().getResource method not workinggetClass().getResource 方法不起作用
【发布时间】:2017-01-28 15:34:13
【问题描述】:
我一直在尝试运行此代码,以便能够查看指定文件夹中的图像,但我不断收到完整的错误列表,我不知道如何修复它们。
错误:线程“AWT-EventQueue-0”中的异常
java.lang.NullPointerException 在
fatface.FatFace.getImages(FatFace.java:27)
Problem is shown on this image
【问题讨论】:
-
请勿发布图片或外部链接,请在此处复制代码。 mcve
标签:
java
image
netbeans-8
【解决方案1】:
尝试使用
ClassLoader.getSystemClassLoader().getResource("fatface/pictures").getFile()
例子
File f = new File(ClassLoader.getSystemClassLoader().
getResource("fatface/pictures/").getFile());
System.out.println(Arrays.deepToString(f.list()));
输出:
[温度.jpg]