The problem is occurring when you are calling setContentView()
method for the second time by passing mapView
setContentView(mapView);
The mapView
belongs to its parent RelativeLayout
. So, you are trying to set this mapView
as activity layout ignoring its parents RelativeLayout
then you are getting the IllegalStateException
...
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.openstreetmaptutorial/com.example.openstreetmaptutorial.MainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
You can solve the problem by removing second setContentView()
method call.