Support Topics Documentation Slack YouTube Blog

Null pointer exception when setting relation to geo


(SnakeEyes) #1

Hello ,
I am using the Java/Android api. I am saving restaurant data, geo point and then linking them

GeoPoint geo = new GeoPoint();
geo.setLatitude(latValue);
geo.setLongitude(lngValue);
geo = Backendless.Geo.savePoint( geo );
ArrayList location = new ArrayList();
location.add( geo );

    try {
        Map ret1 = Backendless.Data.of("Restaurant").save(restaurentHM);
        if (ret1 == null) {
            return false;
        }
        int ret2 = Backendless.Data.of("Restaurant").setRelation(restaurentHM, "GeoLocation:GeoPoint:1", location);
        if (ret2 != 1) {
            return false;
        }

However I am receiving this error in the relation code. I verified on the server and the restaurant data and the geo point are there. They are not linked
The error I am getting is:

BackendlessException{ code: ‘Server.Processing’, message: ‘java.lang.RuntimeException: java.lang.NullPointerException’, extendedData: ‘{}’, detail: ‘java.lang.RuntimeException: java.lang.NullPointerException’ }


(SnakeEyes) #2

I found the issue. I should be using the Map that has objectID in it not just any map. So in my code, I should use ret1. A suggestion: Maybe returned error should mention that it is missing objectId so it is easier to debug