Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

jakarta ee - Get NullPointerException in java EE application on Intellij Idea IDE

I'm trying to run this simple and small application but I don't understand which is the problem and consequently how to fix it.

Here it is the code. It is very simple. One bean invoked by a client application in order to print out in the client terminal the well-known message Hello World. I have created the application by using Intellij Idea 13.0.3 IDE with Server GlassFish 4.0.0, Java JDK 8.0 and Java EE 7.

EDIT

I think I got those errors because I didn't deployed correctly my application. I have found a guide that says that after having created the client application in netbeans environment you have to execute Insert Code -> Call Enterprise Bean. Now how can I do the same thing on Intellij Idea?


package myejb;

import javax.ejb.Remote;

@Remote
public interface HelloBeanRemote
{
    public String sayHello(String name);
}

package myejb;

import javax.ejb.Stateless;

@Stateless
public class HelloBean implements HelloBeanRemote
{
    @Override
    public String sayHello(String name)
    {
        return "Hello, " + name + "!";
    }
}

and the Client application

package myejbclient;

import javax.ejb.EJB;
import myejb.HelloBeanRemote;

public class HelloClient
{
    @EJB
    private static HelloBeanRemote helloBean;

    public static void main(String[] args)
    {
        HelloClient client = new HelloClient();
        client.doConversation();
    }

    public void doConversation()
    {
        System.out.println(helloBean.sayHello("World"));
    }
}

I execute glassfish to deploy the application. it is deployed correctly but when I run the client application I get this error message:

Exception in thread "main" java.lang.NullPointerException
    at myejbclient.HelloClient.doConversation(HelloClient.java:27)
    at myejbclient.HelloClient.main(HelloClient.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

EDIT2

The same code works like a charm in Netbeans IDE having GlassFish installed.

Netbeans IDE

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You haven't assigned hello to anything that's been instantiated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...