Also be aware that there might be devices out there which do not implement
the Geocoder functionality. From the SDK doc:
*The Geocoder class requires a backend service that is not included in the
> core android framework. The Geocoder query methods will return an empty
> list if there no backend service in the platform. Use the isPresent()
> method to determine whether a Geocoder implementation exists.
> *
So you cannot just access the first returned item of the address list. You
must also check its size.
On Wednesday, August 8, 2012 7:13:26 AM UTC-5, Ece Osmanağaoğlu wrote:
>
> I wanna get current location.
> There is null pointer exception in List<Address>
>
> locMan = (LocationManager)
> this.getSystemService(Context.LOCATION_SERVICE);
> gpsProv = LocationManager.GPS_PROVIDER;
> locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000,
> 250, Kampusler.this);
> myGeo = new Geocoder(Kampusler.this, Locale.getDefault());
>
> loc = locMan.getLastKnownLocation(gpsProv);
> try
> {
> List<Address> adres = myGeo.getFromLocation(loc.getLatitude(),
> loc.getLongitude(), 1);
> if(adres != null)
> {
> for(int i=0; i <
> adres.get(0).getMaxAddressLineIndex(); i++)
> {
> result += adres.get(0).getAddressLine(i) + "\n";
> }
> }
> else
> {
> Toast.makeText(Kampusler.this, "Don't get address...",
> Toast.LENGTH_LONG).show();
> }
> }
> catch (Exception e)
> {
> e.printStackTrace();
> Toast.makeText(getApplicationContext(), e.getMessage(),
> Toast.LENGTH_SHORT).show();
> }
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en