【发布时间】:2016-12-17 19:51:02
【问题描述】:
我正在尝试使用按钮打开和关闭地图(更改布局)。
我在MainActivity 中有一个按钮,它打开SecondActivity,这设置maps_layout 正确。
我在地图上有一个按钮。这会正确切换到另一个布局。
当我想切换回来时,我得到Fatal Exception。
我的代码:
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();
}
});
}
}
这是错误日志:
`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`
我认为错误是因为我没有关闭mapy_test 布局,所以当我再次尝试连接到地图时,我有双重身份。
【问题讨论】:
-
你能发布你的 logcat 错误吗?
-
致命异常:主进程:auftour.mrorhan.probieren,PID:2689 android.view.InflateException:二进制 XML 文件第 6 行:二进制 XML 文件第 6 行:膨胀类片段时出错原因: android.view.InflateException: Binary XML file line #6: Error inflating class fragment 原因: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
-
顺便说一句,我认为错误来了,因为我没有关闭“mapy_test”布局,所以当我尝试再次连接到地图时,我有双 ID?
-
我编辑了问题,将错误日志从评论中移到主要问题中。
-
ty 进行编辑 :)
标签: java android google-maps button maps