Boladoad 0 Denunciar post Postado Julho 29, 2011 Criei uma janela usando do netbeans e lá a janela aparece normalmente, ao passar para o eclipse o programa dá null pointer por não conseguir localizar a imagem na linha de código jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Desenhos/DesejaCriartreino.png"))); // NOI18N, alguem sabe como resolver isso? segue o código da classe abaixo: package Janelas; public class JanelaDesejaCriarTreino extends javax.swing.JFrame { /** Creates new form JanelaDesejaCadastrar */ public JanelaDesejaCriarTreino() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setBackground(new java.awt.Color(255, 255, 255)); jPanel1.setMinimumSize(new java.awt.Dimension(600, 500)); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Desenhos/DesejaCriartreino.png"))); // NOI18N jButton1.setFont(new java.awt.Font("Comic Sans MS", 1, 11)); // NOI18N jButton1.setText("CRIAR"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setFont(new java.awt.Font("Comic Sans MS", 1, 11)); // NOI18N jButton2.setText("VOLTAR AO MENU"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(51, 51, 51) .addComponent(jLabel1) .addContainerGap(51, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(83, 83, 83) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 125, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(76, 76, 76)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(61, 61, 61) .addComponent(jLabel1) .addGap(45, 45, 45) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(79, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new JanelaDesejaCriarTreino().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; // End of variables declaration } Compartilhar este post Link para o post Compartilhar em outros sites
Giovanni Ritchie 0 Denunciar post Postado Julho 30, 2011 mostre a tua estrutura de diretorios! Provavelmente a imagem nao está no mesmo sobre o diretorio do .class que você está usando como referencia! Por isso preciso ver como está sua estrutura de diretorios! Compartilhar este post Link para o post Compartilhar em outros sites
Discorpio 1 Denunciar post Postado Setembro 21, 2011 Boa noite a todos. O método "getClass().getRessource(..)" procura por recursos (arquivos/outros) inicialmente que se encontra dentro da pasta "src" do seu projeto. Verifique se a pasta Desenho encontra-se dentro de "src". Compartilhar este post Link para o post Compartilhar em outros sites