理论就是点击不同的地方,将不同的坐标送到一个包含mapview的页面中。详细来说,页面A上有一些选项,页面B是显示A的选择的坐标的地图,点击页面B上的返回按钮返回页面A重新选择。现在遇到了问题,就是程序运行进入A页面,点击一个选项后,在页面B正常显示。但是一旦返还了页面A,再点击另外的选项,这时程序就“Stopped unexpectedly”。经排查是xml的问题。难道是不能重复调用含有mapview的页面么?以下是测试用的简单版代码,页面A无关紧要就不贴了:这个是页面B的xml:
<?xml version="1.0" encoding="utf-8"?>  
  <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:scrollbarStyle="outsideOverlay">
 
  <Button android:text="back" android:id="@+id/b" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
  
  <com.google.android.maps.MapView android:id="@+id/showmap"
    android:layout_width="300px" 
    android:layout_height="300px" 
    android:enabled="true"
  android:clickable="true"
    android:apiKey="0hIYvwPXktV15To8IIlyvjvbG8Gpsf-_1FGBXUg"/>
 
</LinearLayout>这个是引用地图部分的关键代码: public void tryyy()
    { 
          setContentView(R.layout.main);
          status = 5;
          MapView mapView = (MapView) findViewById(R.id.showmap);        MapController mc = mapView.getController();    
         String lon2 = "-0.13357";  String lat2 = "51.5246";
       GeoPoint gp = new GeoPoint((int) (Double.parseDouble(lat2) * 1000000), (int) (Double.parseDouble(lon2) * 1000000));
       mc.animateTo(gp); 
       mc.setZoom(16); 
                
     Button confirmButton = (Button) findViewById(R.id.b);
     confirmButton.setOnClickListener(new View.OnClickListener() {              public void onClick(View view) { 
             onCreate(null);
                
               }});    }Manifest里的权限和uses-library都加了