import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextField;
public class autos extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
String get;
int logic = 0, b;
JFrame frame = new JFrame("Tic Tac Toe");
JTextField text = new JTextField(1);
public autos() {
JButton button = new JButton("LOAD");
add(button);
add(text);
setLayout(null);
button.setBounds(70, 70, 80, 40);
text.setBounds(140, 140, 20, 20);
text.addActionListener(this);
if (duvoi.equals("x")) logic = 1;
else if (get.equals("0")) logic = 2;
else logic = 0;
}
public void paint(Graphics g) {
super.paint(g);
if (logic == 1)
g.drawString("You entered x", 200, 100);
else if (logic == 2)
g.drawString("You entered", 200, 100);
else b = 23;
repaint();
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new autos());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
get = text.getText();
}
}
When I try to run the code,I get these errors:
Exception in thread "main" java.lang.NullPointerException at autos.(autos.java:27) at autos.main(autos.java:48)
I am using eclipse.Why do these errors appear and what can I do to get rid of them?