I am in a dead end and I need help, my mistake is as follows. When loading a table with images from my BD
data% MySQL
I get it
java.lang.nullpointerexception
and I do not know what its cause or motive is. The method I use to load my table is:
private void cargarTabla(){
try {
Connection miComando = AdministradorConfiguracion.obtenerComandoMySql();
CallableStatement obtenerProductos = miComando.prepareCall("call obtener_productos()");
ResultSet rs = obtenerProductos.executeQuery();
//Instanciamos la clase "ImagenTabla" para renderizarla e mostrar las imagenes.
jTablaProducto.setDefaultRenderer(Object.class, new ImagenTabla());
ResultSetMetaData rsmd = rs.getMetaData();
String Titulo[] = {"Nro", "Producto", "Stock", "Precio Costo", "Precio Venta", "Marca", "Descripción", "Categoria", "Proveedor", "Fecha Vecimiento",
"Meses Restantes", "Dias Restantes", "Imagen"};
Object[] fila = new Object[rsmd.getColumnCount()];
modelo = new DefaultTableModel(null, Titulo);
while (rs.next()) {
fila[0] = rs.getInt("Nro");
fila[1] = rs.getString("Producto");
fila[2] = rs.getInt("Stock");
fila[3] = rs.getDouble("Precio Costo");
fila[4] = rs.getDouble("Precio Venta");
fila[5] = rs.getString("Marca");
fila[6] = rs.getString("Descripción");
fila[7] = rs.getString("Categoria");
fila[8] = rs.getString("Proveedor");
fila[9] = rs.getDate("Fecha Vecimiento");
fila[10] = rs.getInt("Meses Restantes");
fila[11] = rs.getInt("Dias Restantes");
Blob blob = rs.getBlob(13);
if (blob != null) {
byte[] data = blob.getBytes(1, (int)blob.length());
BufferedImage img = null;
try {
img = ImageIO.read(new ByteArrayInputStream(data));
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
>>>ImageIcon icono = new ImageIcon(img);<<<
fila[12] = new JLabel(icono);
}else{
fila[12] = "";
}
modelo.addRow(fila);
}
jTablaProducto.setModel(modelo);
jTablaProducto.setRowHeight(64);
ContarFilas();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Error al intentar obtener los productos:\n"
+ e, "Error en la operación", JOptionPane.ERROR_MESSAGE);
}
}
The nullpointerexception
comes to me in the line of ImageIcon icono = new ImageIcon(img);
I would greatly appreciate your help