I am trying to put byte[] to JLabel on netbeans maven Project. I read some solutions and then implement it for me. However when I start application it gives me error lists such as;
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:228)
at org.tutev.envanterys.gui.finger.FrmFinger.btnShowImagesActionPerformed(FrmFinger.java:104)
at org.tutev.envanterys.gui.finger.FrmFinger.access$000(FrmFinger.java:29)
at org.tutev.envanterys.gui.finger.FrmFinger$1.actionPerformed(FrmFinger.java:55)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
Could you please kindly help me where is my mistake and how can I avoid this? Here is my code:
try {
Finger finger = new Finger();
FingerService fingerService = new FingerService();
finger = fingerService.getImage(Long.parseLong("1"));
byte[] image1 = finger.getImage1();
ByteArrayInputStream bais = new ByteArrayInputStream(image1);
BufferedImage img = ImageIO.read(bais);
lblFinger1.setIcon(new ImageIcon(img));
} catch (IOException ex) {
Logger.getLogger(FrmFinger.class.getName()).log(Level.SEVERE, null, ex);
}
When I debug application I see that byte[]
and bais
has data but BufferedImage img
is null.