Note that there are some explanatory texts on larger screens.

plurals
  1. POJava JButton Image
    primarykey
    data
    text
    <p><strong>Hey so I've moved my images to the correct work space folder(src) but i keep getting this error message.....</strong></p> <pre><code>Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.&lt;init&gt;(Unknown Source) at GUI.&lt;init&gt;(GUI.java:20) at main.main(main.java:4) </code></pre> <p><strong>This is the code</strong></p> <pre><code>import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.Icon; import javax.swing.ImageIcon; import java.awt.FlowLayout; public class GUI extends JFrame { private JButton reg; private JButton custom; public GUI(){ super("Welcome"); setLayout(new FlowLayout()); reg = new JButton("reg button"); add(reg); Icon b = new ImageIcon(getClass().getResource("b.png")); Icon a = new ImageIcon(getClass().getResource("a.png")); custom = new JButton("Custom", b); custom.setRolloverIcon(a); add(custom); thehandler handle = new thehandler(); reg.addActionListener(handle); custom.addActionListener(handle); } private class thehandler implements ActionListener{ public void actionPerformed(ActionEvent event){ JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand())); } } } ----------------------- import javax.swing.JFrame; public class main { public static void main(String agrs[]){ GUI page = new GUI(); page.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); page.setSize(300,200); page.setVisible(true); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload