Bom dia Galera!
Estou tentando colocar um logo na lateral do meu sistema, porem ele está me retornando um erro.
package br.com.warehouse.telas;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import javax.swing.JDesktopPane;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
public class TelaPrincipal extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TelaPrincipal frame = new TelaPrincipal();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public TelaPrincipal() {
setResizable(false);
setTitle("Lovato - Sistema de Estoque Aliment\u00EDcio");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 880, 600);
JLabel lblLogo = new JLabel("");
lblLogo.setBounds(660, 40, 200, 200);
ImageIcon imagem = new ImageIcon(TelaPrincipal.class.getResource("E:\\Sistema\\workspace\\prjwarehouse\\src\\\\br\\com\\warehouse\\icones\\logo.png"));
Image imag = imagem.getImage().getScaledInstance(lblLogo.getWidth(), lblLogo.getHeight(), Image.SCALE_DEFAULT);
lblLogo.setIcon(new ImageIcon(imag));
Porem, quando eu executo ele me retorna um erro:
java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at br.com.warehouse.telas.TelaPrincipal.<init>(TelaPrincipal.java:54)
at br.com.warehouse.telas.TelaPrincipal$1.run(TelaPrincipal.java:33)
at java.awt.event.InvocationEvent.dispatch(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.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)
O caminho da imagem está correto…
Ele roda quando eu tiro a instancia ImageIcon imagem = new ImageIcon
Por que isso está acontecendo ?