Android Mobile App

I am currently working on a project that requires me to get the address using reverse geocode. I am able to get the data from the URL but keep getting an error as follows. Would be great if i can get a solution to this problem. Thanks!

“12-19 03:01:54.419 5088-5088/com.junjie.retrofit_location E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.junjie.retrofit_location, PID: 5088
java.lang.NullPointerException: Attempt to invoke virtual method ‘int java.util.ArrayList.size()’ on a null object reference
at com.junjie.retrofit_location.MainActivity$1.onResponse(
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(

Hi JunJie,

This error message is telling you that the object handled is empty/null (Nothing inside the arraylist). To handle this exception, you will need a try-catch-finally statement.

Kai Cong

Hi Kaicong,
Okay will try out the try/catch method, but just wondering is there any solution to retrieve the json under the GeocodeInfo as I’m using retrofit to get the response but keep getting the null object error. Is there a way to get the object such as the buildingname, block, road, etc.


Jun Jie

Hi Jun Jie,

There is a chance for you to retrieve an empty object because some locations do not retrieve any feature information. I am afraid you will have to handle it with appropriate message like “No Location Info” or giving back their LatLng position.

Hope that clarifies.

Kai Cong