Estoy aprendiendo a usar Java y quiero obtener la información de un JTextField y un JComboBox ya los genere en el Jframe el problema es que estoy tratando de obtener su contenido a travez de un metodo y me marca el 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());
}
}
El error es generado al momento de dar clic en el botón Merge
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at pruebas.combo(pruebas.java:67) at pruebas$2.actionPerformed(pruebas.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)