The project compiles to me and works perfectly for me only when I make a CLEAN AND BUILD of it, I get the following error:
run:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 4
at interfaz.Ficha_tecnica_alquiler.jComboBox_bastidorItemStateChanged(Ficha_tecnica_alquiler.java:238)
at interfaz.Ficha_tecnica_alquiler.access$000(Ficha_tecnica_alquiler.java:13)
at interfaz.Ficha_tecnica_alquiler$1.itemStateChanged(Ficha_tecnica_alquiler.java:125)
at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1223)
at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1280)
at javax.swing.JComboBox.contentsChanged(JComboBox.java:1330)
at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:118)
I leave you the code of the classes / methods although I already tell you that everything works OK.
private void jComboBox_bastidorItemStateChanged(java.awt.event.ItemEvent evt) {
//Recogemos en la variable "bastidor" el valor seleccionado en el combobox con el método "getSelectedItem()".
String bastidor = (String) jComboBox_bastidor.getSelectedItem();
//Guardamos en un objecto "v" los datos del bastidor gracias a la función "Conexiones.datos_de_un_bastidor_alquiler(bastidor);".
Object[] v = Conexiones.datos_de_un_bastidor_alquiler(bastidor);
//Otorgamos a los campos jTextField los valores recogidos en el "Object[] v".
textfield_marca.setText(String.valueOf(v[0]));
textfield_modelo.setText(String.valueOf(v[1]));
textfield_matricula.setText(String.valueOf(v[2]));
textfield_disponible.setText(String.valueOf(v[3]));
//Creamos un objecto bidimensional llamado "tabla" donde guardamos los datos de la función "Conexiones.clientes_alquilado_vehiculo(bastidor);".
Object[][] tabla = Conexiones.clientes_alquilado_vehiculo(bastidor);
//Fila de los títulos de la tabla.
String[] titulos = {"NOMBRE", "DNI", "FECHA ALQUILER", "FECHA DE ENTREGA", "ESTADO DEVOLUCION"};
//Agregamos al objeto de tipo DefaultTableModel "dtm" los parámetros necesarios.
dtm = new DefaultTableModel(tabla, titulos);
//Añadimos los datos del "dtm" a la tabla "table_alquiler".
table_alquiler.setModel(dtm);
//tabla.getColumnModel().getColumn(model.findColumn("NombreColumna")).setPreferredWidth(tamaño);
table_alquiler.getColumnModel().getColumn(0).setPreferredWidth(180); //Nombre
table_alquiler.getColumnModel().getColumn(1).setPreferredWidth(180); //DNI
table_alquiler.getColumnModel().getColumn(2).setPreferredWidth(240); //Fecha de alquilado
table_alquiler.getColumnModel().getColumn(3).setPreferredWidth(280); //Fecha de entrega real
table_alquiler.getColumnModel().getColumn(4).setPreferredWidth(300); //Estado devolucion
}
public static Object[] datos_de_un_bastidor_alquiler(String bastidor) {
//Creamos un objeto "v" de 4 valores: marca, modelo, matricula, disponible.
Object[] v = new Object[4];
String bd = Conexiones.bbdd;
Connection c = (Connection) Conexiones.conexion_a_BBDD(bd);
Statement stm;
ResultSet rs;
try {
//Consulta para sacar todos los datos del vehiculo_alquiler de un bastidor.
stm = c.createStatement();
String consulta_de_un_bastidor = "SELECT v.*, va.fecha_v_alquiler, va.disponible, m.nombre FROM vehiculos AS v, vehiculos_alquiler AS va, marca AS m "
+ "WHERE v.bastidor='" + bastidor + "' AND v.bastidor=va.bastidor AND v.marca=m.ID;";
rs = stm.executeQuery(consulta_de_un_bastidor);
//System.out.println("CONSULTA DATOS: Datos de un bastidor en concreto.\n");
rs.next();
String marca = rs.getString("nombre");
String modelo = rs.getString("modelo");
String matricula = rs.getString("matricula");
int disponible = rs.getInt("disponible");
v[0] = marca;
v[1] = modelo;
v[2] = matricula;
v[3] = disponible;
c.close();
} catch (SQLException e) {
e.printStackTrace();
}
return v;
}