Dear Stackoverflow Developers i have to load image as an icon to jmenu from jar.
I am using the following code . It is throwing the null pointer exception but when i am setting the icon with imageicon class in jframe, it is showing the icon in frame
try
{
JMenu menu= new JMenu("");
Icon im1= new ImageIcon(getClass.getResource("path of the images");
menu.setIcon(im1);
}
catch(Exception ex)
{
}
what is the wrong in this code plz help
common issue is that
ImageIcon,Icondoesn’t returns any exception, test forNull valueIcon im1= new ImageIcon why???, those are differentJava Object, have to test ifIconisinstanceofImageIconread turotial about Icon and JMenu / JMenuItem
for example
code