I am trying to open and close maps (changing layouts) with a button.
I have a button in MainActivity
which opens SecondActivity
and this sets maps_layout
correct.
I have a button on the maps. This switches to another layout correctly.
When I want to switch back, I get Fatal Exception
.
My Code:
public class Game extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapy();
}
public void mapy() {
setContentView(R.layout.mapy_test);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map_test);
mapFragment.getMapAsync(this);
Button changetocam = (Button) findViewById(R.id.changetocam);
changetocam.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cam();
}
});
}
public void cam() {
setContentView(R.layout.ingame_masteroverlay_layout);
Button changetomap = (Button) findViewById(R.id.changetomap);
changetomap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapy();
}
});
}
}
Here is the error log:
`FATAL EXCEPTION: main Process: auftour.mrorhan.probieren, PID: 2689 android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class fragment Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment Caused by: java.lang.IllegalArgumentException: Binary XML file line #6: Duplicate id 0x7f0f010b, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment`
I think the error is because I don't close the mapy_test
layout, so I have double id, when I try to connect to the map again.