"AWT-EventQueue-0" java.lang.NullPointerException

0

Mam taki kod

 import java.util.Properties;
import javax.naming.InitialContext;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import st.HelloRemote;

public class HelloClient extends JFrame {
    public HelloClient() {
        super("Hello Client");
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        JButton b1 = new JButton("Access EJB");

        getContentPane().add(b1, BorderLayout.PAGE_END);

        b1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                String msg = "";
                try {
                    // Access JNDI Initial Context.
                    Properties p = new Properties();
                    p.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
                    p.put("java.naming.provider.url","jnp://localhost:1099");
                    p.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
                    InitialContext ctx = new InitialContext(p);
                    // Change jndi name according to your server and ejb
                    HelloRemote remote = (HelloRemote) ctx.lookup("HelloBean/remote");
                    msg = "Message From EJB --> " + remote.sayHello();
                } 
                catch(Exception ex){
                    msg = "Error --> " +  ex.getCause().toString();   // że niby w tym miejscu jest lipa
                }
                JOptionPane.showMessageDialog(HelloClient.this,msg,"Message", JOptionPane.INFORMATION_MESSAGE);
            }
        });
        setSize(200,200);
    } //
    public static void main(String args[]) {
       new HelloClient().setVisible(true);
    } 
}

i dostaje takie błędy co może być przyczyną
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at HelloClient$1.actionPerformed(HelloClient.java:32)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

0

public Throwable getCause()
...
Returns:
the cause of this throwable or null if the cause is nonexistent or unknown.

0
Taruun napisał(a)

co może być przyczyną
PEBKAC

0

ok niewiele mi to powiedziało uprościłem ten kod i teraz wygląda tak:


import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import st.HelloBeanRemote;

public class HelloClient  {
    public static void main(String args[]) throws NamingException {
        // Access JNDI Initial Context.
        String msg="";
                    Properties p = new Properties();
                    p.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
                    p.put("java.naming.provider.url","jnp://localhost:1099");
                    p.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
                    InitialContext ctx = new InitialContext(p);
                    // Change jndi name according to your server and ejb
                    HelloBeanRemote rem = (HelloBeanRemote) ctx.lookup("HelloBean/remote");
                    msg = "Message From EJB --> " + rem.sayHello();
                    System.out.println(msg);

    }
}

jednak nadal ma jakiś problem możecie poradzić o co może mu chodzić?
Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to st.HelloBeanRemote
at HelloClient.main(HelloClient.java:23)
Java Result: 1

0

Google: javax.naming.reference cannot be cast to

0

Ehh tak już próbowałem no nic noc jest długa może znajdę coś co będzie napisane przystępnym językiem i się przyda :-(

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0