I am writing a chat server application in eclipse ide how i wish to change the jar default image icon but all attempt end either in error or the line of code running with change the icon. here is where i put the code.

setIconImage(new ImageIcon(ClassLoader.getSystemResource("chatbutton.jpg")).getImage());

and here is the error i got.

Exception in thread "main" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(Unknown Source)
    at ChatMain.main(ChatMain.java:29)

Recommended Answers

All 3 Replies

Look at the API documentation for getSystemResource:
Returns: A URL object for reading the resource, or null if the resource could not be found.

Now I create an object like this Icon b = new ImageIcon(getClass().getResource("chaticon.jpg")); how do I call it so it could change my java default icon?

Icon b = new ImageIcon(getClass().getResource("/chaticon.jpg"));
use "/" at starting of image location

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.