Why does my icon handling code throw a NullPointerException?

后端 未结 6 2238
梦如初夏
梦如初夏 2020-12-16 07:12

I have added an image for my button,but when I run that frame this exception will be thrown .why?please help me.

init:

deps-jar:
compile-single:
run-single:         


        
6条回答
  •  情话喂你
    2020-12-16 07:31

    In order to fix this, the images need to be copied in the bin directory - not in src directory.

    Otherwise you will get null all the time on getClass().getResource("image.png"). The path is not null and you can set it as the above - only if you copy the images that you need inside the binary directory, where .class files for your project are located.

    This fixed the problem. Let me know if I helped in this.

    Ioana

提交回复
热议问题