-2

I have created FiltersQueryAdapter as mainAdapter which has been passed to setupPhotoFilters Method where mainadapter is assisgned to setAdapter. Is possible that as parseGeoPointfromLocation not being within the scope of FiltersQueryApdapter its returning null what i cloud do in this case?

  /*
  * Helper method to get the Parse GEO point representation of a location
  */
    public ParseGeoPoint geoPointFromLocation(Location loc) {
        return new ParseGeoPoint(loc.getLatitude(), loc.getLongitude());
    }


    FiltersQueryAdapter mainAdapter = new FiltersQueryAdapter(this, PhotoFiltersAdapter.class
            , new ParseRecyclerQueryAdapter.QueryFactory() {
        public ParseQuery create() {
            Location myLoc = (currentLocation == null) ? lastLocation : currentLocation;
            ParseQuery query = ParseQuery.getQuery("PlaceFilters");
            //query.include("user");
            query.orderByAscending("GeoArea");
            query.whereWithinKilometers("GeoArea", geoPointFromLocation(myLoc), radius);
            query.setLimit(6);
            return query;
        }
    });


    private void setupPhotoFilters() {
        rvFilters.setHasFixedSize(true);
        rvFilters.setAdapter(mainAdapter);
        rvFilters.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    }
Sagar Atalatti
  • 486
  • 1
  • 8
  • 21
  • within GeoLocationHelper ? – Sagar Atalatti Feb 18 '16 at 20:32
  • read the error message. the problem is on line 174 of TakePhotoActivity.java. probably caused from GeoLocationHelper not having set currentBestLocation to anything. – FredK Feb 18 '16 at 20:33
  • Seems like an issue that would happen if the args to access the Google Play Location Services were not set properly. I followed [this tutorial](http://developer.android.com/training/location/index.html) to set up the location services on an app. Worked perfectly for me. Let me know how it goes. – Debosmit Ray Feb 18 '16 at 20:36
  • Asking the same question again and again will not help... – Selvin Feb 18 '16 at 20:36
  • @DebosmitRay so I need to initlize GoogleApiClient in my mainActivity to start location services. And then I can call getLatitude in my TakePhotoActivity class? – Sagar Atalatti Feb 18 '16 at 20:46
  • @SagarAtalatti Nope. You need to call the connect() function on the GoogleApiClient instance first. If you are just concerned with the Location Services, you need to add that API to the GoogleApiClient instance. There could be a bunch of things going wrong in your implementation since you haven't shown your onConnected(..), etc, which would make the answer too long. Please refer to the tutorial link. – Debosmit Ray Feb 18 '16 at 20:51
  • @DebosmitRay I have made the GoogleApiClient methods which I tested is working but I have an issue with the parseGeoPointfromLocation which used in the FiltersQueryAdapter and has been assigned to setAdapater I have re-edited my question please do check once. – Sagar Atalatti Feb 19 '16 at 11:11
  • I am not conversant with the Parse SDK. You should post your issue as a separate question. – Debosmit Ray Feb 19 '16 at 11:36

1 Answers1

1

You're making the assumption that this line always return a non-null value:

currentBestLocation = locationManager
    .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

The javadoc suggests that it can be null, so you should always check it before it's used. You're propagating that value via getCurrentLocation() so check it there.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441