Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Always throw Null Pointer Exception

 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the error message ?
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You´re welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic