Wednesday, August 8, 2012

[android-developers] ReverseGeocoding NullPointerException

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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate