This is my class with the GUI:
import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.JPasswordField; import javax.swing.JOptionPane; import javax.swing.JButton; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JOptionPane; public class GUI extends JFrame{ private JButton reg; private JButton custom; public GUI(){ super("The Tittle"); setLayout(new FlowLayout()); reg = new JButton("reg Button"); add(reg); Icon b = new ImageIcon(getClass().getResource("x.png")); Icon c = new ImageIcon(getClass().getResource("y.png")); custom = new JButton("Custom", b); custom.setRolloverSelectedIcon(c); add(custom); HandlerClass handler = new HandlerClass(); reg.addActionListener(handler); custom.addActionListener(handler); } private class HandlerClass implements ActionListener{ public void actionPerformed(ActionEvent event){ JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand())); } } }
then my main class:
Eclipse error message:Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:205) at GUI.<init>(GUI.java:26) at Apples.main(Apples.java:7)
i think the problem is to do with my images not being recognised. I put them in my source in User>...>workspace>src which is correct as far as i know. From what i know the images should show up if i look at my src file in eclipse but they dont. I tried changing the file type from .png to .jpg but it makes no difference. Help much appreciated!
--- Update ---
i solved this but im not sure how to delete the thread lol
--- Update ---
i solved this but im not sure how to delete the thread lol