我正在尝试使用 lat ,lng 获取地址。
但是粘贴下面的代码不起作用。我真的很感激任何帮助。
我总是遇到异常,而不是值是什么错误?
提前致谢。
googleMap.setOnMapClickListener((OnMapClickListener) new OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
// TODO Auto-generated method stub
final LatLng pt = point;
marker2 = googleMap.addMarker(new MarkerOptions()
.position(pt)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
final ProgressDialog progressDialog = ProgressDialog.show(
MainActivity.this,
"Searching Location....", "Please wait....");
new Thread(new Runnable(){
public void run(){
try {
Toast.makeText(getBaseContext(), GeocoderUtil.getAddress(marker2.getPosition(), MainActivity.this), 5).show();
}catch(Exception e)
{
runOnUiThread(new Runnable() {
public void run() {
progressDialog.dismiss();
Toast.makeText(getBaseContext(),"error.", 5).show();
}
});
}}}
).start();
例外:
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)