users@glassfish.java.net

Null pointer execption

From: <glassfish_at_javadesktop.org>
Date: Thu, 10 Jul 2008 02:46:13 PDT

Hi

I am using Glassfish V2 with Netbeans 6.1 on Windows XP.

I have a simple application with a JFrame and main class that simply updates a label on the form with a string that comes from a EJB.

When I call the EJB from the main class it works, but when i call the ejb form the JFrame (MainForm) class I get a null pointer exception.

What am I doing wrong?

Here the is main class:

[b]package enterpriseappee5;

/**
 *
 * @author Louw
 */
public class Main {
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainForm().setVisible(true);
            }
        });
    }
}[/b]


Here is the JFrame (MainForm) class:

[b]package enterpriseappee5;

import ejb.SessionRemote;
import javax.ejb.EJB;

/**
 *
 * @author Louw
 */
public class MainForm extends javax.swing.JFrame {
    @EJB
    private static SessionRemote sessionBean;

    /** Creates new form MainForm */
    public MainForm() {
        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() {

        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("jLabel1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addContainerGap(279, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jLabel1))
                .addContainerGap(266, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    jLabel1.setText(sessionBean.getResult());
}

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration

}[/b]
[Message sent by forum member 'hendrel' (hendrel)]

http://forums.java.net/jive/thread.jspa?messageID=285616