Load Image from Jar: Always null

后端 未结 2 1842
囚心锁ツ
囚心锁ツ 2020-12-10 08:41

Looked at other posts on SO and they did not solve this issue.

I\'m trying to load an image from my jar file. It is continuously coming up as null. The image is loca

相关标签:
2条回答
  • 2020-12-10 09:16

    Which jar file is the image in, compared with the class you're using to call getResource? If they're loaded by the same classloader, it should be fine.

    Have you double-checked that the jar file actually contains the file?

    Are you sure that your classloader is actually using the jar file at all (rather than .class files directly on disk, for example)?

    If you have a short but complete program which demonstrates the problem, that would really help. (A console app would be ideal... we don't need to see the image, after all.)

    0 讨论(0)
  • 2020-12-10 09:18

    try this :

    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/BLOCK.png"));
    
    0 讨论(0)
提交回复
热议问题