#1 2012-05-24 17:19:41

BenoitB
Member
Registered: 2012-05-14
Posts: 47

Compilation problem, NPE

Hi

I'm trying to make a filter on my table prt_adh on the value prt_cat. I xant it to be equals to "A"

So here is what i put on the filter:

              prt_adh.PRT_CAT.equals("A")

But when this value is null, i've got a Null pointer exception.

My fileds is nullable, so I'm telling myself let's make a condition that don't take null value in the filter, with this code:
     
              (null != prt_adh.PRT_CAT)?prt_adh.PRT_CAT.equals("A") : null

And then the message error is that he's Expecting to find integer on stack

I don't know how to do now.

Thanks for your help !

Offline

#2 2012-05-24 17:24:54

janhess
Member
Company: Newcastle University
Registered: 2009-05-19
Posts: 1123

Re: Compilation problem, NPE

which component is the rule in?

Offline

#3 2012-05-24 17:31:42

BenoitB
Member
Registered: 2012-05-14
Posts: 47

Re: Compilation problem, NPE

For your information I'm using TMap component.

And now I tried to make the filter directly on the SQL command on the prt table

That is to say on the request SELECT .... FROM PRT WHERE PRT.PRT_CAT='A'"

And with this filter it works, so is the TMap filter bugged or did I miss something ??

Thanks for your help !

Offline

#4 2012-05-24 17:40:22

janhess
Member
Company: Newcastle University
Registered: 2009-05-19
Posts: 1123

Re: Compilation problem, NPE

That's probably the best solution.

Offline

#5 2012-05-24 20:51:17

phobucket
Member
Company: Knoetry
Registered: 2010-07-27
Posts: 146
Website

Re: Compilation problem, NPE

Benoit,

Your solution will work well, but this info may also be helpful in other scenarios:

Generally when using .equals()  it is safer to put the constant first, as in "A".equals(prt_adh.PRT_CAT).  Because "A" will always be a string, you can always use the .equals() method on it.  If you use prt_adh.PRT_CAT.equals("A"), prt_adh.PRT_CAT may be null, and the null data type has no .equals() method, which is what was causing your problem.

Thanks,
Ben

Offline

#6 2012-05-25 09:02:48

BenoitB
Member
Registered: 2012-05-14
Posts: 47

Re: Compilation problem, NPE

Thanks for your answer, indeed I have no longer this problem of NPE but still I've got the result I want with my solution but not with yours.

Could you tell me why i don't have the same result ?

Thanks for your help !

Offline

Board footer

Powered by FluxBB