我想知道我的谷歌地图有什么问题。当我尝试将一个类的纬度和经度的值解析为另一个类以使用谷歌地图时,它不起作用。
我从“”获取 URL,我需要“纬度”和“经度”的值来解析到我的谷歌地图。我能够检索纬度和经度的数据。
但是,当我尝试将值解析为谷歌地图时,它不起作用,给我的强制关闭错误。我可以知道我的代码有什么问题吗?
我的onclick部分代码:
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("coords", "lat: " + KEY_LATITUDE + " long: " + KEY_LONGITUDE);
Intent intent = new Intent(SingleMenuItemActivity.this, map.class);
intent.putExtra("LAT", KEY_LATITUDE.toString());
intent.putExtra("LON", KEY_LONGITUDE.toString());
startActivity(intent);
地图.java
public class map extends FragmentActivity {
// double lat;
// double lng;
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_shown);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = fm.getMap();
map.animateCamera(CameraUpdateFactory.zoomIn());
String lat = null;
String lon = null;
map.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(lat, lon),
14.0f));
}
private LatLng LatLng(String lat, String lon) {
// TODO Auto-generated method stub
Bundle extras = getIntent().getExtras();
lat = extras.getString("LAT");
lon = extras.getString("LON");
return null;
}
}
日志错误:
08-14 15:21:47.300: E/AndroidRuntime(24718): FATAL EXCEPTION: main
08-14 15:21:47.300: E/AndroidRuntime(24718): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fambond/com.example.fambond.map}: java.lang.NullPointerException
08-14 15:21:47.300: E/AndroidRuntime(24718): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
08-14 15:21:47.300: E/AndroidRuntime(24718): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-14 15:21:47.300: E/AndroidRuntime(24718): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-14 15:21:47.300: E/AndroidRuntime(24718): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-14 15:21:47.300: E/AndroidRuntime(24718): at android.os.Handler.dispatchMessage(Handler.java:99)
08-14 15:21:47.300: E/AndroidRuntime(24718): at android.os.Looper.loop(Looper.java:130)
08-14 15:21:47.300: E/AndroidRuntime(24718): at android.app.ActivityThread.main(ActivityThread.java:3691)
08-14 15:21:47.300: E/AndroidRuntime(24718): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 15:21:47.300: E/AndroidRuntime(24718): at java.lang.reflect.Method.invoke(Method.java:507)
08-14 15:21:47.300: E/AndroidRuntime(24718): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
08-14 15:21:47.300: E/AndroidRuntime(24718): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
08-14 15:21:47.300: E/AndroidRuntime(24718): at dalvik.system.NativeStart.main(Native Method)
08-14 15:21:47.300: E/AndroidRuntime(24718): Caused by: java.lang.NullPointerException
08-14 15:21:47.300: E/AndroidRuntime(24718): at maps.al.a.a(Unknown Source)
08-14 15:21:47.300: E/AndroidRuntime(24718): at maps.ag.af.a(Unknown Source)
08-14 15:21:47.300: E/AndroidRuntime(24718): at maps.ag.s.a(Unknown Source)
08-14 15:21:47.300: E/AndroidRuntime(24718): at maps.ag.an.a(Unknown Source)
08-14 15:21:47.300: E/AndroidRuntime(24718): at bkw.onTransact(SourceFile:83)
08-14 15:21:47.300: E/AndroidRuntime(24718): at android.os.Binder.transact(Binder.java:279)
08-14 15:21:47.300: E/AndroidRuntime(24718): at com.google.android.gms.maps.internal.IGoogleMapDelegate$a$a.moveCamera(Unknown Source)
08-14 15:21:47.300: E/AndroidRuntime(24718): at com.google.android.gms.maps.GoogleMap.moveCamera(Unknown Source)
08-14 15:21:47.300: E/AndroidRuntime(24718): at com.example.fambond.map.onCreate(map.java:28)
08-14 15:21:47.300: E/AndroidRuntime(24718): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
08-14 15:21:47.300: E/AndroidRuntime(24718): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-14 15:21:47.300: E/AndroidRuntime(24718): ... 11 more