I am learning to use Java and I want to get the information of a JTextField and a JComboBox already generate them in the Jframe the problem is that I am trying to get its content through a method and it marks me the error
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
public class pruebas extends JFrame {
static String[] lista = { "RUTEO", "ESTATICO","BGP" };
private JPanel contentPane;
static String[][][] ValueTypes;
static JComboBox combo_rutmen;
static JTextField tf_REFERENCIA;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
pruebas frame = new pruebas();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public pruebas() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
ValueTypes = new String[3][50][4];
JComboBox combo_rutmen = new JComboBox(lista);
combo_rutmen.setBounds(128, 63, 78, 20);
contentPane.add(combo_rutmen);
JButton btnMerge = new JButton("Merge");
btnMerge.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
combo();
}
});
btnMerge.setBounds(190, 228, 89, 23);
contentPane.add(btnMerge);
JTextField tf_REFERENCIA = new JTextField();
tf_REFERENCIA.setText("a32");
tf_REFERENCIA.setBounds(128, 94, 86, 20);
contentPane.add(tf_REFERENCIA);
tf_REFERENCIA.setColumns(10);
}
static void combo() {
System.out.println("REFERENCIA " + tf_REFERENCIA.getText());
System.out.println("Ruteo " + combo_rutmen.getSelectedItem().toString());
}
}
The error is generated when clicking on the Merge button
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at pruebas.combo (pruebas.java:67) at $ 2.actionPerformed tests (tests.java:54) at javax.swing.AbstractButton.fireActionPerformed (Unknown Source) at javax.swing.AbstractButton $ Handler.actionPerformed (Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source) at javax.swing.DefaultButtonModel.setPressed (Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased (Unknown Source) at java.awt.Component.processMouseEvent (Unknown Source) at javax.swing.JComponent.processMouseEvent (Unknown Source) at java.awt.Component.processEvent (Unknown Source) at java.awt.Container.processEvent (Unknown Source) at java.awt.Component.dispatchEventImpl (Unknown Source) at java.awt.Container.dispatchEventImpl (Unknown Source) at java.awt.Component.dispatchEvent (Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent (Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent (Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent (Unknown Source) at java.awt.Container.dispatchEventImpl (Unknown Source) at java.awt.Window.dispatchEventImpl (Unknown Source) at java.awt.Component.dispatchEvent (Unknown Source) at java.awt.EventQueue.dispatchEventImpl (Unknown Source) at java.awt.EventQueue.access $ 500 (Unknown Source) at java.awt.EventQueue $ 3.run (Unknown Source) at java.awt.EventQueue $ 3.run (Unknown Source) at java.security.AccessController.doPrivileged (Native Method) at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (Unknown Source) at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (Unknown Source) at java.awt.EventQueue $ 4.run (Unknown Source) at java.awt.EventQueue $ 4.run (Unknown Source) at java.security.AccessController.doPrivileged (Native Method) at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (Unknown Source) at java.awt.EventQueue.dispatchEvent (Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters (Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter (Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy (Unknown Source) at java.awt.EventDispatchThread.pumpEvents (Unknown Source) at java.awt.EventDispatchThread.pumpEvents (Unknown Source) at java.awt.EventDispatchThread.run (Unknown Source)