问题
getFromLocationName()
alsways throws a NullPointerException
in the Android 2.2 emulator but it's working fine in the Android 1.6 emulator.
This is my code snippet:
Geocoder geo = new Geocoder(GeocoderAppActivity.this, Locale.getDefault());
try {
List<Address> add = geo.getFromLocationName("Tagore Road,Rajkot", 1);
while (add.size() == 0) {
Log.e("Girish", "in while");
add = geo.getFromLocationName("Tagore Road,Rajkot", 1);
}
}
What is wrong?
回答1:
In the emulator, are you using the regular Android 2.2
, or the Google Apis [Android 2.2]
version?
If you use the regular Android 2.2 one, it won't work. As far as I know it does not have the functionality to fulfill your actions. Open your SDK manager and download the Google Apis [Android 2.2] and create an AVD with that. Then try again, it should work.
回答2:
It's a known bug which they never fixed see service not available I think you will find that it works in the the API level 7 emulator.
回答3:
Yes this is a Bug but I think it shall run on device.
来源:https://stackoverflow.com/questions/8503693/geocoder-works-in-1-6-but-not-in-2-2-emulator