在Intellij Idea IDE上的Java EE应用程序中获取NullPointerException [英] Get NullPointerException in java EE application on Intellij Idea IDE

查看:329
本文介绍了在Intellij Idea IDE上的Java EE应用程序中获取NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行这个简单而小巧的应用程序,但我不明白哪个是问题因此如何解决它。

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.

这里是码。这很简单。客户端应用程序调用的一个bean,用于在客户端终端中打印出众所周知的消息Hello World。我使用Intellij Idea 13.0.3 IDE和Server GlassFish 4.0.0,Java JDK 8.0和Java EE 7创建了应用程序。

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

我认为我收到了这些错误,因为我没有正确部署我的应用程序。我找到了一个指南,说明在netbeans环境中创建客户端应用程序后,您必须执行Insert Code - > Call Enterprise Bean。现在我怎样才能在Intellij Idea上做同样的事情?

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"));
    }
}

我执行glassfish来部署应用程序。它是正确部署但当我运行客户端应用程序时,我收到此错误消息:

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

相同的代码就像使用GlassFish的Netbeans IDE中的魅力一样安装。

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

Netbeans IDE

Netbeans IDE

推荐答案

在您的客户代码中,您可以随时为您的hello服务分配引用。

In your client's code, at any time you assign the reference to your hello service.

当您在应用程序服务器中将它用作glassfish,jboss等时。容器读取注释并插入可用的EJB。

When you use it in an application server as glassfish, jboss, etc. The container reads the annotations and insert the available EJB.

对于您的客户端,您需要一个< a href =http://docs.oracle.com/cd/E19229-01/819-0600/msgappclient.html\"rel =nofollow>应用程序客户端容器或自己搜索引用

For your client you need an Application Client Container or search the reference by your self

来自Glassfish FAQ 如何做我访问远程EJB ... 你需要InitialContext,如果需要你需要配置服务器和端口

From the Glassfish FAQ How do I access a Remote EJB ... you need InitialContext, if is necessary you need to configure the server and port

使用ACC,你需要创建一个企业项目并在您的服务器中部署,Netbeans的一个简单示例可以帮助您: https:/ /netbeans.org/kb/docs/java ee / entappclient.html

With an ACC, you need to create an enterprise project and deploy in your server, an easy example from Netbeans can help you: https://netbeans.org/kb/docs/javaee/entappclient.html

这篇关于在Intellij Idea IDE上的Java EE应用程序中获取NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆