views:

59

answers:

1
response.setHeader(keys[i].toString(),value);

in a servlet is throwing null pointer exception even though none of keys[i] or value are null why is it so?

+6  A: 

One of the following is true:

  1. response is null
  2. keys is null
  3. keys[i] is null
  4. the exception is not thrown from the line you posted.

A 29% acceptance rate isn't likely to attract much help.

duffymo
About #4, error messages sometimes appear to be from the line after the actual problem; could anything there be null?
Lord Torgamus
Well now that you added that line about the acceptance rate, you should change the post to "TWO of the following are true."
Lord Torgamus
True enough, Lord Torgamus. 8)
duffymo
Actually, I think there is one more case: i is of type Integer ('int' wrapper class) and i is null. I believe the auto-"unboxing" code will result in a NullPointerException.
Bert F