Hi there,
I have this null pointer exception error in my code which I can't fix. I'm just trying to create an interface which can display an image, text and 12 buttons all at once. I've checked out loads of other threads, but I can't see where the Null entry is in my code?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class PhoneInterface1 extends JFrame
{
private JPanel imagePanel, numberPad;
private JTextField text;
public PhoneInterface1()
{
JButton[] buttons = new JButton[12];
this.add("North", imagePanel);
this.add("Centre", text);
numberPad.setLayout(new GridLayout(4,3));
for(int i=0; i<12; i++)
{
buttons[i] = new JButton(""+i);
numberPad.add(buttons[i]);
}
this.add("South", numberPad);
this.pack();
this.setVisible(true); //displays the frame
}
public static void main(String args[])
{
new PhoneInterface1();
}
}
..and the error I'm getting is:
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at javax.swing.JFrame.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at PhoneInterface1.<init>(PhoneInterface1.java:14)
at PhoneInterface1.main(PhoneInterface1.java:29)
Can anyone spot the bug?
Ger.