0

I am trying to read a json file, and from it, a double, but I came across NullPointerException in the following situation, while there is no apparent error in it.

double longitude = (double) json_restaurant.get("longitude");

error:

java.lang.NullPointerException

I tried to check if it wasn't working, by calling System.out.println(longitude) after the above-mentioned code snippet, and the terminal does display the correct value of longitude.

Where am I going wrong, if anywhere?

user207421
  • 305,947
  • 44
  • 307
  • 483

1 Answers1

0

Check the JSON. Does it have the longitude? If it does not get("longitude") might return null. It is something that you can not assign to primitive double. That will throw NPE.

Try using Double instead

pirho
  • 11,565
  • 12
  • 43
  • 70