我正在尝试在 Google 地图中添加此按钮。单击后,它将显示该地点的位置。但是,当我运行它时,它给了我一个强制关闭错误。
我现在要让它工作的按钮是“CITY”按钮的另外两个,我还没有设置它。
这是我的 logcat 错误。
07-22 14:50:19.260: E/AndroidRuntime(11261): FATAL EXCEPTION: main
07-22 14:50:19.260: E/AndroidRuntime(11261): java.lang.NoSuchMethodError: com.example.googlemap.MainActivity.getFragmentManager
07-22 14:50:19.260: E/AndroidRuntime(11261): at com.example.googlemap.MainActivity.onCreate(MainActivity.java:26)
07-22 14:50:19.260: E/AndroidRuntime(11261): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
07-22 14:50:19.260: E/AndroidRuntime(11261): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
07-22 14:50:19.260: E/AndroidRuntime(11261): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
07-22 14:50:19.260: E/AndroidRuntime(11261): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-22 14:50:19.260: E/AndroidRuntime(11261): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
07-22 14:50:19.260: E/AndroidRuntime(11261): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 14:50:19.260: E/AndroidRuntime(11261): at android.os.Looper.loop(Looper.java:130)
07-22 14:50:19.260: E/AndroidRuntime(11261): at android.app.ActivityThread.main(ActivityThread.java:3691)
07-22 14:50:19.260: E/AndroidRuntime(11261): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 14:50:19.260: E/AndroidRuntime(11261): at java.lang.reflect.Method.invoke(Method.java:507)
07-22 14:50:19.260: E/AndroidRuntime(11261): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
07-22 14:50:19.260: E/AndroidRuntime(11261): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
07-22 14:50:19.260: E/AndroidRuntime(11261): at dalvik.system.NativeStart.main(Native Method)
这是我的编码。
MainActivity.java
public class MainActivity extends FragmentActivity {
private final LatLng LOCATION_BURNABY = new LatLng(49.27645, -122.917587);
private final LatLng LOCATION_SURREY = new LatLng(49.187500, -122.849000);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
public void onClick_City(View v){
CameraUpdate update = CameraUpdateFactory.newLatLng(LOCATION_BURNABY);
map.animateCamera(update);
}
public void onClick_Burnaby(View v){
}
public void onClick_Surrey(View v){
}
}