【发布时间】:2013-09-02 08:12:24
【问题描述】:
我正在尝试获取邮政编码,但无法获取邮政编码(邮政编码)。我可以获取当前城市,但是当我尝试获取邮政编码时,它给了我一个空指针异常。 谁能帮帮我。
final Geocoder gcd = new Geocoder(getApplicationContext(),
Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0) Log.d(addresses.get(0).getLocality()); // I can get city name here.
Log.d(addresses.get(0).getPostalCode();// here i am getting nullpoiter exception
【问题讨论】:
-
阅读链接中已接受答案的第二条评论。
-
AddressLine 的其他含义?
-
这意味着 - developer.android.com/reference/android/location/…, double, int)。然后
addresses.get(1)).getPostalCode()或尝试使用 2,3,4。读完这篇文章后 - 看看这里 - stackoverflow.com/questions/16515682/… -
当我这样使用时,我得到了以下异常 09-02 java.lang.IndexOutOfBoundsException: Invalid index 3, size is 1