package Sound;
import javax.swing.*;
public class practice_1 {
JFrame frame;
public static void main(String[] args)
{
practice_1 gogo=new practice_1();
gogo.go();
}
public void go()
{
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button =new JButton("click me");
frame.getContentPane().add(button);
frame.setSize(300,300);
frame.setVisible(true);
}
}
this is error code
Exception in thread "main" java.lang.NullPointerException
at Sound.practice_1.go(practice_1.java:16)
at Sound.practice_1.main(practice_1.java:12)
我无法理解为什么会发生NUllPointerException。我对NUllPointerException的了解是,当我使用nullpointer对象时,它会发生NUllPointerException。是吗?