0

I am using a Map in java i am getting null pointer exception when i use this if(!GenericValidator.isBlankOrNull(itemsImagesMap.get(item.getuserId()).toString()))

The map does not contain this userId but i have checked !GenericValidator.isBlankOrNull but then also i am getting null pointer exception..

1
  • What is MAP? Do you mean java.util.Map? Then, if you nest serveral method invocations without further explanation, it is hard for us to tell what is going on, and which one might cause your NPE. Commented Aug 27, 2012 at 19:06

3 Answers 3

2

Either item is null and you get the exception since you call getuserId on null or itemsImagesMap.get(item.getuserId()) returns null and you call toString on null

Sign up to request clarification or add additional context in comments.

1 Comment

Just check if(item == null) or if(item.getUserId() == null) to verify
2

You should probably do some checks in your code. Something like:

if (item != null && item.getuserId() != null && itemsImagesMap.get(item.getuserId()) != null) {
  // do the rest of the logic here
}

Comments

0

You shoul -really- avoid arm-long lines ;)

Split it into multiple lines, it will be far more easy to debug.

(Sorry, this does not answer the question, but do this and post the result).

Did you put something corresponding to the item.getuserId() key in your map ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.