Estoy desarrollando una aplicación en Java Netbeans con base de datos phpMyAdmin. Ya he elaborado algunas más, pero ahora se me ha presentado este problema:
Dicha aplicación sirve para capturar datos de un almacén que lleva un control de entradas y salidas de papelería, así como de material eléctrico y herramientas que se tienen que dar de baja y las que no, crearen un inventario donde se incluye marca, modelo y en ocasiones el número de serie; captura todo en los respectivos campos y realiza un par de operaciones aritméticas, el detalles es que cuando presiono el botón Guardar me indica esta serie de líneas:
run: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at almacen.Insumos.cboarticuloActionPerformed(Insumos.java:616) at almacen.Insumos.access$000(Insumos.java:12) at almacen.Insumos$1.actionPerformed(Insumos.java:164) at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1260) at javax.swing.JComboBox.setSelectedItem(JComboBox.java:588) at almacen.Insumos.btnguardarActionPerformed(Insumos.java:688) at almacen.Insumos.access$200(Insumos.java:12) at almacen.Insumos$3.actionPerformed(Insumos.java:183) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6505) at javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at java.awt.Component.processEvent(Component.java:6270) at java.awt.Container.processEvent(Container.java:2229) at java.awt.Component.dispatchEventImpl(Component.java:4861) at java.awt.Container.dispatchEventImpl(Container.java:2287) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) at java.awt.Container.dispatchEventImpl(Container.java:2273) at java.awt.Window.dispatchEventImpl(Window.java:2719) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:688) at java.awt.EventQueue$3.run(EventQueue.java:686) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) at java.awt.EventQueue$4.run(EventQueue.java:702) at java.awt.EventQueue$4.run(EventQueue.java:700) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:699) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Siendo estas líneas el código correspondiente:
package almacen;
import java.sql.Connection;
/*import Conexion.Conectar;*/
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class Insumos extends javax.swing.JFrame {
DefaultTableModel modelo;
public Insumos() {
initComponents();
modelo = new DefaultTableModel();
modelo.addColumn("Articulo");
modelo.addColumn("Stock");
modelo.addColumn("Cantidad Solicitada");
modelo.addColumn("Unidad");
modelo.addColumn("Marca");
modelo.addColumn("Modelo");
modelo.addColumn("Usuario");
modelo.addColumn("Extensión Cisco");
modelo.addColumn("Unidad Administrativa");
modelo.addColumn("MOvimiento");
this.tblinsumos.setModel(modelo);
}
/*void CargarTablaDatos(String valor) {
String[] titulos = {"Articulo", "Stock", "Cantidad Solicitada", "Unidad", "Marca", "Modelo", "Usuario", "Extensión Cisco", "Unidad Administrativa", "Movimiento"};
modelo = new DefaultTableModel(null, titulos);
String[] registro = new String[18];
Conexion mysql = new Conexion();
Connection cn = mysql.Conectar();
String sSQL;
sSQL = "SELECT Articulo, Stock, Cantidad_Solicitada, Unidad, Marca, Modelo, Usuario, Extension_Cisco, Movimiento FROM insumos "
+ "WHERE CONCAT(Usuario, ' ', Extension_Cisco, ' ', Unidad_Administrativa, ' ')LIKE '%" + valor + "%'";
try {
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery(sSQL);
int c = 1;
while (rs.next()) {
registro[0] = rs.getString("Articulo");
registro[1] = rs.getString("Stock");
registro[2] = rs.getString("Cantidad_Solicitada");
registro[3] = rs.getString("Unidad");
registro[4] = rs.getString("Marca");
registro[5] = rs.getString("Modelo");
registro[6] = rs.getString("Usuario");
registro[7] = rs.getString("Extension_Cisco");
registro[8] = rs.getString("Unidad_Administrativa");
registro[9] = rs.getString("Movimiento");
modelo.addRow(registro);
c++;
}
tblinsumos.setModel(modelo); //variable de la tabla
this. tblinsumos.setModel(modelo); //variable de la tabla
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex);
}
}*/
public void FormatoConsulta(){
tblinsumos.getColumnModel().getColumn(0).setPreferredWidth(10);
tblinsumos.getColumnModel().getColumn(1).setPreferredWidth(50);
tblinsumos.getColumnModel().getColumn(2).setPreferredWidth(50);
tblinsumos.getColumnModel().getColumn(3).setPreferredWidth(50);
tblinsumos.getColumnModel().getColumn(4).setPreferredWidth(100);
tblinsumos.getColumnModel().getColumn(5).setPreferredWidth(100);
tblinsumos.getColumnModel().getColumn(6).setPreferredWidth(50);
tblinsumos.getColumnModel().getColumn(7).setPreferredWidth(50);
tblinsumos.getColumnModel().getColumn(8).setPreferredWidth(50);
tblinsumos.getColumnModel().getColumn(6).setPreferredWidth(50);
}
void BuscarDatosEditar(String id){
String sSQL;
String art="", stk="", cantsol="", unit="", mrc="", mod="", user="" ;
String extcisco="", uadmva="",mov="";
Conexion mysql = new Conexion();
Connection cn = mysql.Conectar();
sSQL = "SELECT Articulo, Stock, Cantidad_Solicitada, Unidad. Marca, Modelo, Usuario, "+
"SELECT Extension_Cisco, Unidad_Administrativa, Movimiento FROM insumos"+
"WHERE Articulo = "+id;
try {
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery(sSQL);
while(rs.next()){
art = rs.getString("Articulo");
stk = rs.getString("Stock");
cantsol = rs.getString("Cantidad_Solicitada");
unit = rs.getString("Unidad");
mrc = rs.getString("Marca");
mod = rs.getString("Modelo");
user = rs.getString("Usuario");
extcisco = rs.getString("Extension_Cisco");
uadmva = rs.getString("Unidad_Administrativa");
mov = rs.getString("Movimiento");
}
}catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex);
}
}
private void btnborrarActionPerformed(java.awt.event.ActionEvent evt) {
btnborrar.transferFocus();
txtstockA.setText("");
txtcantsol.setText("");
txtmodelo.setText("");
txtext_c.setText("");
}
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Menu mn = new Menu();
mn.setVisible(true);
}
private void txtcantsolActionPerformed(java.awt.event.ActionEvent evt) {
txtcantsol.transferFocus();
}
private void txtext_cActionPerformed(java.awt.event.ActionEvent evt) {
txtext_c.transferFocus(); }
private void txtmodeloActionPerformed(java.awt.event.ActionEvent evt) {
txtmodelo.transferFocus();
}
private void btnuevoActionPerformed(java.awt.event.ActionEvent evt) {
btnuevo.transferFocus();
cboarticulo.setSelectedItem("");
txtstockA.setText("");
txtcantsol.setText("");
cbounidad.setSelectedItem("");
cbomarca.setSelectedItem("");
txtmodelo.setText("");
cbouser.setSelectedItem("");
txtext_c.setText("");
txtuadmva.setText("");
cbomov.setSelectedItem("");
}
private void cbomovActionPerformed(java.awt.event.ActionEvent evt) {
cbomov.transferFocus();
}
private void cboarticuloActionPerformed(java.awt.event.ActionEvent evt) {
cboarticulo.transferFocus();
String aeropuerto = cboarticulo.getSelectedItem().toString();
if (aeropuerto.equals("León Mata Jesús Arturo")) {
txtstockA.setText("");
}else if(aeropuerto.equals("2")) {
txtstockA.setText("");
}else if(aeropuerto.equals("3")) {
txtstockA.setText("");
}else if(aeropuerto.equals("4")) {
txtstockA.setText("");
}else if(aeropuerto.equals("5")) {
txtstockA.setText("");
}else if(aeropuerto.equals("6")) {
txtstockA.setText("");
}else if(aeropuerto.equals("7")) {
txtstockA.setText("");
}else if(aeropuerto.equals("8")) {
txtstockA.setText("");
}else if(aeropuerto.equals("9")) {
txtstockA.setText("");
}
}
private void txtstockAActionPerformed(java.awt.event.ActionEvent evt) {
txtstockA.transferFocus();
}
private void cbounidadActionPerformed(java.awt.event.ActionEvent evt) {
cbounidad.transferFocus();
}
private void cbomarcaActionPerformed(java.awt.event.ActionEvent evt) {
cbomarca.transferFocus();
}
private void cbouserActionPerformed(java.awt.event.ActionEvent evt) {
cbouser.transferFocus();
String usuario = cbouser.getSelectedItem().toString();
if (usuario.equals("León Mata Jesús Arturo")) {
txtext_c.setText("18679");
txtuadmva.setText("CIAAC");
}else if(usuario.equals("2")) {
txtext_c.setText("18300");
txtuadmva.setText("Área Central");
}else if(usuario.equals("3")) {
txtext_c.setText("007");
txtuadmva.setText("Almacen");
}else if(usuario.equals("4")) {
txtext_c.setText("18300");
txtuadmva.setText("Dirección de Control");
}else if(usuario.equals("5")) {
txtext_c.setText("007");
txtuadmva.setText("Dirección de Verificación");
}else if(usuario.equals("6")) {
txtext_c.setText("18300");
txtuadmva.setText("Licencias");
}else if(usuario.equals("7")) {
txtext_c.setText("007");
txtuadmva.setText("Terminal 1");
}else if(usuario.equals("8")) {
txtext_c.setText("18300");
txtuadmva.setText("Terminal 2");
}else if(usuario.equals("9")) {
txtext_c.setText("007");
txtuadmva.setText("CIAAC");
}
}
/* String accion = "Insertar";*/
private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {
String []Datos = new String[10];
Datos[0] = cboarticulo.getSelectedItem().toString();
cboarticulo.setSelectedItem(null);
Datos[1] = txtstockA.getText();
txtstockA.setText(null);
Datos[2] = txtcantsol.getText();
txtcantsol.setText(null);
Datos[3] = cbounidad.getSelectedItem().toString();
cbounidad.setSelectedItem(null);
Datos[4] = cbomarca.getSelectedItem().toString();
cbomarca.setSelectedItem(null);
Datos[5] = txtmodelo.getText();
txtmodelo.setText(null);
Datos[6] = cbouser.getSelectedItem().toString();
cbouser.setSelectedItem(null);
Datos[7] = txtext_c.getText();
txtext_c.setText(null);
Datos[8] = txtuadmva.getText();
txtuadmva.setText(null);
Datos[9] = cbomov.getSelectedItem().toString();
cbomov.setSelectedItem(null);
modelo.addRow(Datos);
/*cbomov.transferFocus();*/
/* Conexion mysql = new Conexion();
Connection cn = mysql.Conectar();
String desc, stk, cantsol, unit, mrc, mod, user, extcisco, mov;
String sSQL;
String mensaje;
desc = cboarticulo.getSelectedItem().toString();
stk = txtstockA.getText();
cantsol = txtcantsol.getText();
unit=cbounidad.getSelectedItem().toString();
mrc=cbomarca.getSelectedItem().toString();
mod=txtmodelo.getText();
user=cbouser.getSelectedItem().toString();
extcisco=txtext_c.getText();
mov=cbomov.getSelectedItem().toString();
sSQL = "INSERT INTO insumos(Articulo, Stock, Cantidad_Solicitada, "+
"Unidad, Marca, Modelo, Usuario, Extension_Cisco, Movimiento, "+
"VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ? )";
mensaje = "Datos insertados exitosamente";
try {
PreparedStatement pst = cn.prepareStatement(sSQL);
pst.setString(1,desc);
pst.setString(2,stk);
pst.setString(3,cantsol);
pst.setString(4,unit);
pst.setString(5,mrc);
pst.setString(6,mod);
pst.setString(7,user);
pst.setString(8,extcisco);
pst.setString(9,mov);
int n = pst.executeUpdate();
if (n > 0)
{
JOptionPane.showMessageDialog(null, mensaje);
}
}catch (SQLException ex)
{
JOptionPane.showMessageDialog(null, ex);
} */
}
private void btnentActionPerformed(java.awt.event.ActionEvent evt) {
int num1 = 0;
int num2 = 0;
num1 = Integer.parseInt(this.txtstockA.getText());
num2 = Integer.parseInt(this.txtcantsol.getText());
int saldo = num1 + num2;
/* txtstockA.setText(String.valueOf(saldo)); */
txtstockA.setText(String.valueOf(saldo));
/*txtcantres.setText(null);*/
txtcantres.setText(String.valueOf(saldo));
/*num1 = Integer.parseInt(this.txtstockA.getText());
num2 = Integer.parseInt(this.txtcantsol.getText());
int saldo = num1 + num2;*/
/* txtstockA.setText(String.valueOf(saldo)); */
/*txtstockA.setText(String.valueOf(saldo));
txtcantres.setText(String.valueOf(saldo)); */
}
private void btnsalActionPerformed(java.awt.event.ActionEvent evt) {
int num1 = 0;
int num2 = 0;
num1 = Integer.parseInt(this.txtstockA.getText());
num2 = Integer.parseInt(this.txtcantsol.getText());
int saldo = num1 - num2;
txtcantres.setText(String.valueOf(saldo));
/*txtcantres.setText(null);*/
txtstockA.setText(String.valueOf(saldo));
/* num1 = Integer.parseInt(this.txtstockA.getText());
num2 = Integer.parseInt(this.txtcantsol.getText());
int saldo = num1 - num2;
txtcantres.setText(String.valueOf(saldo));
txtstockA.setText(String.valueOf(saldo)); */
}
private void txtuadmvaActionPerformed(java.awt.event.ActionEvent evt) {
txtuadmva.transferFocus();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txtBuscarActionPerformed(java.awt.event.ActionEvent evt) {
txtBuscar.transferFocus();
}
private void txtcantresActionPerformed(java.awt.event.ActionEvent evt) {
txtcantres.transferFocus();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Insumos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Insumos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Insumos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Insumos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Insumos().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnborrar;
private javax.swing.JButton btnent;
private javax.swing.JButton btnguardar;
private javax.swing.JButton btnmodificar;
private javax.swing.JButton btnsal;
private javax.swing.JButton btnuevo;
private javax.swing.JComboBox cboarticulo;
private javax.swing.JComboBox cbomarca;
private javax.swing.JComboBox cbomov;
private javax.swing.JComboBox cbounidad;
private javax.swing.JComboBox cbouser;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tblinsumos;
private javax.swing.JTextField txtBuscar;
private javax.swing.JTextField txtcantres;
private javax.swing.JTextField txtcantsol;
private javax.swing.JTextField txtext_c;
private javax.swing.JTextField txtmodelo;
private javax.swing.JTextField txtstockA;
private javax.swing.JTextField txtuadmva;
// End of variables declaration
/* private void CargarTablaDatos(String string) {
throw new UnsupportedOperationException("Not yet implemented");
}*/
}
Ya revisé todas las líneas y rediseñe el formulario varias veces y sucede esto, no se cómo solucionar estos detalles.