aspose file tools*
The moose likes Beginning Java and the fly likes NullPointerException... what is left to check? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NullPointerException... what is left to check?" Watch "NullPointerException... what is left to check?" New topic
Author

NullPointerException... what is left to check?

Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
I am getting a NullPointerException on the "detail page" of our application.
So I assume it is something in the detail page section of my class that is throwing the NullPointerException.

But I am checking what looks to be all I can check for a null value. This is just the piece that sets values if on a detail page.



Is there something I am missing?

Because I am using an include to call this class I only get an error on the include page for example:

javax.faces.FacesException: javax.el.ELException: /store/shop/layout/template.xhtml @62,52 value="#{coreMetrics.buildCoreMetricsString()}": java.lang.NullPointerException
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

In that piece of code I see four possibilities:
- cm_ScriptName is null
- customerSession is null
- customerSession.getSelectedItem() returns null
- cm_output_common is null


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
I originally set some of the variables to ""; is that a fair approach?

For example near the top of the class I set:



So I feel that eliminates 2 possibilities.

Could you show me how to test for customerSession and customerSession.getSelectedItem() having a null value?
Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
HI Gang.

I came up with this to do checks on the objects.



I hope it works, we are going to deploy and hopefully not see the dreaded NullPointerException anymore.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Why are you doing all those != null checks, rather than displaying them on screen. You need to find where the nulls are coming from.Alternative:Note the %b tag will take foo != null, or foo alone as an argument, displaying "false" from any null reference or false boolean/Boolean and "true" from anything else, including primitives, as far as I can remember.
Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
Hi. If my return type for the class is a String.

Will the below be forced on to my web page? I tried it like shown but nothing appeared on my web page.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
You would expect that printout at your command line or terminal.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18901
    
    8

Dan Acuff wrote:Hi. If my return type for the class is a String.

Will the below be forced on to my web page? I tried it like shown but nothing appeared on my web page.



If the code is in a web application, then no. It will probably go to one of the application server's log files, but exactly which one is server-dependent.

Of course if your question is how to make debugging output appear on the web page, well, you do know how to make text appear on the web page, don't you? Just do that.
Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
Thanks for clearing the up! I was starting to get a bit confused.

Yes I can return values to the web-app screen.

The biggest problem I am having is actually reproducing the error. It's like it happens 1 time on a deployment and then it never happens again.

So I am thinking maybe the customerSession was blank or something similar.. but even that does not make sense since you have to be signed in (thereby having a customerSession) before being able to see the detail page where the last 3 reports of it occuring have happened.

It get's tricky when it happens as rarely as it is since I don't know how to reproduce the conditions.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException... what is left to check?