RESOLVIDO - Dúvida com imagem

olá pessoal
tenho um aplicativo que abre uma figura, clicando nela abre um menuitem
quando roda pelo netbeans funciona
ao criar o jar e mandar para meu cliente
a figura não aparece nem o menuitem
e aparece a mensagem de erro
como resolver

C:\jar\teste>java -jar JMaisBB.jar
Uncaught error fetching image:
java.lang.NullPointerException
        at sun.awt.image.URLImageSource.getConnection(Unknown Source)
        at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
        at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
        at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
        at sun.awt.image.ImageFetcher.run(Unknown Source)

codigo fonte

        final PopupMenu popup = new PopupMenu();
        Image icone = createImage("/images/tray.gif");
        trayIcon = new TrayIcon(icone);
        final SystemTray tray = SystemTray.getSystemTray();
        trayIcon.setImageAutoSize(true);
................
        private Image createImage(String path) {
                return new ImageIcon(path).getImage();
        }

Tenta fazer assim quando a imagem irá ficar dentro do .JAR

em vez de

altere para

testa ai

O que deve estar acontecendo é que o programa não está achando a imagem…pelo caminho que vc passou…

Funciona da maneira que o Ivan Alves fez, só complementando:

java.net.URL img = getClass().getResource("/images/tray.gif"); new JMenuItem("Novo", new ImageIcon(img));

Tome cuidado também que dentro do .jar os arquivos são tratados de forma case sensitive.
Ou seja, letras maiúsculas e minúsculas devem estar idênticas, tanto na pasta quanto no nome do arquivo.

fiz as seguintes alterações

        final TrayIcon trayIcon2 = new TrayIcon(createImage("/images/tray.gif", "teste"));
        SystemTray tray = SystemTray.getSystemTray();
        trayIcon2.setImageAutoSize(true);

....................

    protected static Image createImage(String path, String description) {
        URL imageURL = TrayIcon.class.getResource(path);
        
        if (imageURL == null) {
            System.err.println("error " + path);
            return null;
        } else {
            return (new ImageIcon(imageURL, description)).getImage();
        }
    }

ao rodar pelo netbeans apareceu a figura normalmente e o menu popup tambem abriu normalmente
ao rodar o .jar criado pelo netbeans via dos ( java -jar meujar.jar ) em outra pasta diferente do meu projeto
ele abriu o systray, apareceu a imagem, mas deu o mesmo erro no dos e o menu popup nao esta abrindo

Uncaught error fetching image:
java.lang.NullPointerException

as pastas e nomes do arquivos estão ok

resolvido

http://javafree.uol.com.br/artigo/882523/Criar-um-unico-JAR-com-NetBeans.html

estou com o mesmo problema…

no meu caso, pelo netbeans executa tranquilamente, porem no prompt da o erro:


Uncaught error fetching image:    
java.lang.NullPointerException    
    at sun.awt.image.URLImageSource.getConnection<Unknown Source>    
    at sun.awt.image.URLImageSource.getDecoder<Unknown Source>    
    at sun.awt.image.InputStreamImageSource.doFetch<Unknown Source>    
    at sun.awt.image.ImageFetcher.fetchloop<Unknown Source>    
    at sun.awt.image.ImageFetcher.run<Unknown  Source>  

no erro nao me diz a linha, ai fui atras manualmente e achei


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(janelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(janelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(janelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(janelaPrincipal.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() {
                internalFrameJanelaPrincipal = new janelaPrincipal();
              
                System.out.println("111");
                internalFrameJanelaPrincipal.setVisible(true);
                System.out.println("222");

            }
        });
    }

o problema esta no .setvisible nessa linha que ocorre o erro…

percebi tb que quando crio o .jar ele me traz a o seguinte


Compiling 125 source files to C:\Users\CeSaR\Desktop\ADMClin\ADMclin\build\classes
warning: [options] bootstrap class path not set in conjunction with -source 1.6
Note: C:\Users\CeSaR\Desktop\ADMClin\ADMclin\src\janelaPrincipal\jIFLogin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
Copying 84 files to C:\Users\CeSaR\Desktop\ADMClin\ADMclin\build\classes

acreidot que isso tenha a ver com o erro…
vou tentar esse tutorial que corrigiu o seu problema, dps posto se funcionou ou nao…