JDev
JDev

Reputation: 2551

Google Maps -> MapView -> creation of a constructor -> RuntimeException

I try to write one application for Google Maps.

Tell me, what is my mistake?

If you write like this, all of the works, the card is loaded.

public class TravelMapActivity extends MapActivity {
  private MapView mapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.travel_map_activity);
        mapView = (MapView)findViewById(R.id.travelMapView);
    }
}

And if you create a constructor, I get these errors here.

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.travel_map_activity);
    mapView = new MapView(this, getResources().getString(R.string.google_maps_api_key));
}


 java.lang.RuntimeException: Unable to start activity ComponentInfo{de.ai.mi.maptrack/de.ai.mi.maptrack.activities.TravelMapActivity}: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity

 Caused by: java.lang.IllegalStateException: You are only allowed to
 have a single MapView in a MapActivity

thanks

Upvotes: 0

Views: 280

Answers (1)

Michele
Michele

Reputation: 6131

With the v1 google maps android api you only allowed one MapView at a time. You instantiate one MapView in your XML travel_map_activity i guess, so when you try to create another one with

mapView = new MapView(this, getResources().getString(R.string.google_maps_api_key));

you get the Exception. Try remove the MapView from the XML to solve this.

Upvotes: 1

Related Questions