theDeck.setIcon(new ImageIcon(getClass().getResource("/Cards-1.png")));
Above is code that i set an icon of a jlabel. The program structure is shown here
My question is when I try to run the program using command line, it will give me a nullpointer exception. But if i run the same problem using intellij IDE or gradle, it works fine. What is the reason here?
This is the exception that it throws
System.out.println(getClass().getResource("/").getPath());
I tried to figure out the root directory of the image when running gradle, and it shows me it is in (something)/build/classes/java/main/. I think my main question is why changing the classpath will solve the problem? My image is not in the path, how does the program find the image?