此刻我非常无助。运行此程序时出错:
import java.awt.*;
import javax.swing.*;
public class Puzzle extends JFrame {
static Puzzle m_fenster;
private JPanel ahead, center, buttom;
private JButton ol, om, or, ml, mm, mr, ul, um, ur;
Puzzle(String titel)
{
super(titel);
setLayout(new FlowLayout());
ahead = new JPanel();
center = new JPanel();
buttom = new JPanel();
ol = new JButton();
om = new JButton();
ol = new JButton();
ml = new JButton();
mm = new JButton();
mr = new JButton();
ul = new JButton();
um = new JButton();
ur = new JButton();
ol.setIcon(new ImageIcon("aheadLeft.png"));
om.setIcon(new ImageIcon("aheadCenter.png"));
or.setIcon(new ImageIcon("aheadRight.png"));
ml.setIcon(new ImageIcon("centerLeft.png"));
mm.setIcon(new ImageIcon("centerCenter.png"));
mr.setIcon(new ImageIcon("centerRight.png"));
ul.setIcon(new ImageIcon("bottomLeft.png"));
um.setIcon(new ImageIcon("bottomCenter.png"));
ur.setIcon(new ImageIcon("bottomRight.png"));
ahead.add(ol);
ahead.add(om);
ahead.add(or);
add(ahead);
center.add(ml);
center.add(mm);
center.add(mr);
add(center);
bottom.add(ul);
bottom.add(um);
bottom.add(ur);
add(bottom);
}
public static void main(String[] args) {
m_window = new Puzzle("Puzzle");
m_window.setSize(800,700);
m_window.pack();
m_window.setVisible(true);
}
}
我确定文件夹中存在这些文件。代码可以毫无问题地编译,但是在运行错误时
Exception in thread "main" java.lang.NullPointerException
at Puzzle.<init>(Puzzle.java:30)
at Puzzle.main(Puzzle.java:55)
这可能是一个非常简单的错误。 任何的想法?