aspose file tools*
The moose likes Servlets and the fly likes Always throw Null Pointer Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Always throw Null Pointer Exception" Watch "Always throw Null Pointer Exception" New topic
Author

Always throw Null Pointer Exception

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

When i try to run this code it rans well but in console it shows an NullPointerException always.Eventhough the variable contains some data it throws a exception.Please tell me why it occurs? Ofcourse itsn't interrupt the flow of the project, i dont want any such exceptions to be thrown.

EDITED :


Never try to be a hard-worker. Be a smart-worker.
My Blog
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
To handle null values, you should not catch NullPointerException. It´s a RuntimeException, which usually indicate a fault in the code (thus, a fault of the developer). You should avoid RuntimeExceptions by simply coding the right way. To handle null values, you need to add a nullcheck.

E.g.

To find out what request parameters actually are available, print the parameter map:
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

But the interests array was not null at any time.So the NullPointerException seems weird for me. The interests.length's minimum value is always 1,coz i select atleast one value.

So please tell me whats the exact cause of the problem?

I also try printing the value of interests.length and ensure that the array is not null, but why still the problem persists?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Can you post the error message ?
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Thanks BalusC. I just check the interests array for null and throw my own error message.This will be easier than i expected.
Thats fixed!!!
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You´re welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Always throw Null Pointer Exception
 
Similar Threads
Cant use object from another class
Text box value is not being completely filled with request attribute
Posting to bump up my count...
The x900 effect ?
WA #1.....word association