我正在使用这段代码:
String address = "";
Geocoder geoCoder = new Geocoder( getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(latitude ,longitude , 1);
if (addresses.size() > 0)
{
for (int index = 0;
index < addresses.get(0).getMaxAddressLineIndex(); index++)
address += addresses.get(0).getAddressLine(index) + " "; }
}
catch (IOException e) {
e.printStackTrace();
}
googleMap_v2.animateCamera(CameraUpdateFactory.zoomTo(15));
current_location.setText("Latitude:" + latitude + ", Longitude:"+ longitude );
current_address.setText("current Address :" + address );
googleMap_v2.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("current status"));
}}
这在平板电脑上完美运行,但在移动设备上给了我这个例外。在过去 72 小时内无法弄清楚这一点。如果有人能告诉我应该添加什么,我真的很感激?提前致谢。
例外:
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.maps.maps.MainActivity$1.onMapClick(MainActivity.java:442)
at com.google.android.gms.maps.GoogleMap$.onMapClick(Unknown Source)
at com.google.android.gms.maps.internal.h$a.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:297)
at bor.a(SourceFile:93)
at maps.af.q.b(Unknown Source)
at maps.ap.bo.b(Unknown Source)
at maps.ap.bk.onSingleTapConfirmed(Unknown Source)
at maps.bt.g.onSingleTapConfirmed(Unknown Source)
at maps.bt.i.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4945)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)