Android 6.0 access fine location -


i have code location. problem not in permission.

   public location getlocation() {     location location = null;     locationmanager locationmanager = (locationmanager) getsystemservice(context.location_service);      if (activitycompat.checkselfpermission(this, manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(this, manifest.permission.access_coarse_location) != packagemanager.permission_granted) {      }     location = locationmanager.getlastknownlocation(locationmanager.gps_provider);     locationmanager.requestlocationupdates(locationmanager.gps_provider, 0, 0, locationlistener);     return location; } 

this how location.

    lat = location.getlatitude();     lng = location.getlongitude();      latlng mylocation = new latlng(lat, lng); 

error message :

java.lang.nullpointerexception: attempt invoke virtual method 'double android.location.location.getlatitude()' on null object reference 

i got lost in this. please what's wrong?


Comments