问题描述
为什么我有 NullPointerException
?我做了一切正确!我有2个简单的课程,这不可能是错的!对不起,愚蠢的名字,但我评论几乎所有的代码,它仍然不起作用。
Why I have NullPointerException
? I have done everything right! I have 2 easy classes and it can't be wrong! Sorry for stupid names but I commented almost all code and it still not working!
Caused by: java.lang.NullPointerException
at pl.take.server.model.WholesaleREST.getCars(WholesaleREST.java:34) [:]
休息类:
@Stateless
@Path("/wholesale")
public class WholesaleREST{
@EJB
private WholesaleEJB2 wholesaleEJB2;
@GET
@Path("/get")
public String getCars() {
String string = wholesaleEJB2.createClient2(); //LINE 34
return string;
}
EJB类:
@Stateless
public class WholesaleEJB2 {
public String createClient2() {
return("Hello world!");
}
}
推荐答案
'不太熟悉EJB,但是看起来你的名为wholesaleEJB2的数据成员为null。也许如果你更改了声明该成员阅读的行
I'm not too familiar with EJB, but it looks like your data member named wholesaleEJB2 is null. Perhaps if you change the line that declares that member to read
private WholesaleEJB2 wholesaleEJB2 = new WholesaleEJB2();
你不会有NullPointerException。我在这里假设WholesaleEJB2有一个无参数的构造函数,因为你不会在该类中显示任何构造函数。
you would not have a NullPointerException. I'm assuming here that WholesaleEJB2 has a no-argument constructor, since you do not show any constructor in that class.
这篇关于ejb注入中的NullPointerException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!