imperiumlabs / GeoFirestore-Android

GeoFirestore for Android - Realtime location queries with Firestore
MIT License
123 stars 36 forks source link

java.lang.NullPointerException: Location doesn't exist #34

Closed jayeshbabuav closed 5 years ago

jayeshbabuav commented 5 years ago

When I run the following code,

geoFirestore.getLocation(getItem("documentId", new GeoFirestore.LocationCallback()
                {
                    @Override
                    public void onComplete(GeoPoint geoPoint, Exception e)
                    {
                           e.printStackTrace();
                    }
                });

I get this exception:

java.lang.NullPointerException: Location doesn't exist
2019-08-30 14:32:01.322 2834-2834/in.hashcoder.dishyumm W/System.err:     at org.imperiumlabs.geofirestore.GeoFirestore$getLocation$2.onSuccess(GeoFirestore.kt:195)
2019-08-30 14:32:01.322 2834-2834/in.hashcoder.dishyumm W/System.err:     at org.imperiumlabs.geofirestore.GeoFirestore$getLocation$2.onSuccess(GeoFirestore.kt:16)
2019-08-30 14:32:01.322 2834-2834/in.hashcoder.dishyumm W/System.err:     at com.google.android.gms.tasks.zzn.run(Unknown Source:4)
2019-08-30 14:32:01.323 2834-2834/in.hashcoder.dishyumm W/System.err:     at android.os.Handler.handleCallback(Handler.java:873)
2019-08-30 14:32:01.323 2834-2834/in.hashcoder.dishyumm W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
2019-08-30 14:32:01.323 2834-2834/in.hashcoder.dishyumm W/System.err:     at android.os.Looper.loop(Looper.java:214)
2019-08-30 14:32:01.323 2834-2834/in.hashcoder.dishyumm W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6986)
2019-08-30 14:32:01.323 2834-2834/in.hashcoder.dishyumm W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2019-08-30 14:32:01.323 2834-2834/in.hashcoder.dishyumm W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
2019-08-30 14:32:01.323 2834-2834/in.hashcoder.dishyumm W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)

My setLocation() works fine and location is getting entered in database fine.

Supercaly commented 5 years ago

What's doing the function getItem()?

jayeshbabuav commented 5 years ago

sorry I forgot to remove that getItem() while copying the code:

geoFirestore.getLocation("documentId", new GeoFirestore.LocationCallback()
                {
                    @Override
                    public void onComplete(GeoPoint geoPoint, Exception e)
                    {
                           e.printStackTrace();
                    }
                });

this is the actual code

Supercaly commented 5 years ago

The function returns a NullPointerException because the queried geolocation is null; this can depend on two factors:

  1. In the database, your data is not set correctly with "l" and "g" fields
  2. The "l" field of your data is not correctly set, it needs to be a GeoPoint or a List<Double>
bhavin-chauhan commented 5 years ago

sorry I forgot to remove that getItem() while copying the code:

geoFirestore.getLocation("documentId", new GeoFirestore.LocationCallback()
                {
                    @Override
                    public void onComplete(GeoPoint geoPoint, Exception e)
                    {
                           e.printStackTrace();
                    }
                });

this is the actual code

The function returns a NullPointerException because the queried geolocation is null; this can depend on two factors:

  1. In the database, your data is not set correctly with "l" and "g" fields
  2. The "l" field of your data is not correctly set, it needs to be a GeoPoint or a List<Double>

I am facing same issue and I've checked my firestore database there is entry of l and g https://www.screencast.com/t/7FGNG0eYzJ6 I've write this code, Let me know if I made any mystake

geoFirestore.getLocation(documentId, object : GeoFirestore.LocationCallback {
            override fun onComplete(geoPoint: GeoPoint?, exception: Exception?) {
                if(exception == null &&geoPoint!=null ){
                }
                else{
                }
                }
                  })

W/System.err: java.lang.NullPointerException: Location doesn't exist W/System.err: at org.imperiumlabs.geofirestore.GeoFirestore$getLocation$2.onSuccess(GeoFirestore.kt:195) W/System.err: at org.imperiumlabs.geofirestore.GeoFirestore$getLocation$2.onSuccess(GeoFirestore.kt:16) W/System.err: at com.google.android.gms.tasks.zzn.run(Unknown Source:4) W/System.err: at android.os.Handler.handleCallback(Handler.java:873) W/System.err: at android.os.Handler.dispatchMessage(Handler.java:99) W/System.err: at android.os.Looper.loop(Looper.java:201) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6806) W/System.err: at java.lang.reflect.Method.invoke(Native Method) W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

bhavin-chauhan commented 5 years ago

sorry I forgot to remove that getItem() while copying the code:

geoFirestore.getLocation("documentId", new GeoFirestore.LocationCallback()
                {
                    @Override
                    public void onComplete(GeoPoint geoPoint, Exception e)
                    {
                           e.printStackTrace();
                    }
                });

this is the actual code how you solved this issue, Can you please guide me so I can check my issue