You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by georgenis <ge...@googlemail.com> on 2012/07/26 09:56:17 UTC
NullPointerException but i would like hide it
Hi guys,
i have got a problem about NullPointer-Exceptions....on my EJB i have got a
method....this one:
public String[] findOnlineUser() {
Query query = entityManager.createQuery("SELECT x FROM UserInformation
x WHERE x.online='"+true+"'");
List<UserInformation> userList = (List<UserInformation>)
query.getResultList();
String[] users = new String[userList.size()];
int i=0;
for(UserInformation user:userList) {
users[i] = user.getId();
i++;
}
if(userList.size()==0)
return new String[] {};
return users;
}
On my testprogramm I have got a source code looks like this....
UserService userService =
service.getPort(UserService.class);
String[] onlineUsers = userService.findOnlineUser("myId");
System.out.println(onlineUsers);
My Output > null
But in my method i try to hide the result of "null". Is there any mistake or
is it because XML-Transformation via Webservices (Data - to SOAP - to Data)?
Kind of Regards
george
--
View this message in context: http://openejb.979440.n4.nabble.com/NullPointerException-but-i-would-like-hide-it-tp4656534.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: NullPointerException but i would like hide it
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Ok without code to reproduce try to 1) check the returned value, 2)
serialize it with jaxb
I think 2 is the issue. Maybe try returning a list
- Romain
Le 30 juil. 2012 11:56, "georgenis" <ge...@googlemail.com> a écrit :
> Hi Romain,
>
> there is no "real" NPE...my service sends me just "null" back, but i tried
> to hide "null" with an empty array?! (You can see it in my method i wrote
> in
> my first entry) if(userList.size()==0) return new String[]! But I get only
> null back? any ideas & workaround?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/NullPointerException-but-i-would-like-hide-it-tp4656534p4656585.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: NullPointerException but i would like hide it
Posted by georgenis <ge...@googlemail.com>.
Hi Romain,
there is no "real" NPE...my service sends me just "null" back, but i tried
to hide "null" with an empty array?! (You can see it in my method i wrote in
my first entry) if(userList.size()==0) return new String[]! But I get only
null back? any ideas & workaround?
--
View this message in context: http://openejb.979440.n4.nabble.com/NullPointerException-but-i-would-like-hide-it-tp4656534p4656585.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: NullPointerException but i would like hide it
Posted by Romain Manni-Bucau <rm...@gmail.com>.
can you send the stacktrace?
btw getresultlist can return null i think with some providers.
- Romain
2012/7/26 georgenis <ge...@googlemail.com>
> Hi guys,
>
> i have got a problem about NullPointer-Exceptions....on my EJB i have got a
> method....this one:
>
> public String[] findOnlineUser() {
> Query query = entityManager.createQuery("SELECT x FROM
> UserInformation
> x WHERE x.online='"+true+"'");
> List<UserInformation> userList = (List<UserInformation>)
> query.getResultList();
> String[] users = new String[userList.size()];
> int i=0;
> for(UserInformation user:userList) {
> users[i] = user.getId();
> i++;
> }
>
> if(userList.size()==0)
> return new String[] {};
>
> return users;
> }
>
> On my testprogramm I have got a source code looks like this....
>
> UserService userService =
> service.getPort(UserService.class);
> String[] onlineUsers = userService.findOnlineUser("myId");
> System.out.println(onlineUsers);
>
> My Output > null
> But in my method i try to hide the result of "null". Is there any mistake
> or
> is it because XML-Transformation via Webservices (Data - to SOAP - to
> Data)?
>
> Kind of Regards
>
> george
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/NullPointerException-but-i-would-like-hide-it-tp4656534.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>