英文:
Problems loading resource into java application from filesystem
问题
我正在尝试在NetBeans(适用于Mac)上在标签上设置图像图标。
我在项目文件夹中导入图像后设置了图像:
screenshot of selected image
当我尝试运行项目时,出现以下错误:
Exception in thread "main" java.lang.NullPointerException
at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:217)
at Laboratorio.Login.initComponents(Login.java:52)
at Laboratorio.Login.<init>(Login.java:17)
at Laboratorio.Main.main(Main.java:26)
Login.java:52:
labelLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Laboratorio/Immagini/logo_550.png")));
图像的路径是:
/Users/salvatore/NetBeansProjects/Laboratorio/src/main/java/Laboratorio/Immagini/logo_550.png
有人能帮我吗?谢谢!
英文:
I'm trying to set an image icon on a label on NetBeans (for Mac).
I set the image after imported it in the project folder:
screenshot of selected image
When I try to run the project it fails with these errors:
Exception in thread "main" java.lang.NullPointerException
at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:217)
at Laboratorio.Login.initComponents(Login.java:52)
at Laboratorio.Login.<init>(Login.java:17)
at Laboratorio.Main.main(Main.java:26)
Login.java:52:
labelLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Laboratorio/Immagini/logo_550.png")));
The path of the image is:
/Users/salvatore/NetBeansProjects/Laboratorio/src/main/java/Laboratorio/Immagini/logo_550.png
Can someone help me, please?
Thanks!
答案1
得分: 0
我解决了。
我之前使用Java和Gradle(从未使用过)... 我一直使用Java和Ant。现在它使用相同的代码正常工作。
英文:
I solved.
I was using Java with Gradle (never used)... I always used Java with Ant. Now it works correctly with the same code.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论