我有一个滑块菜单,它使用片段类。 每当我点击我的“户外”标签时,Outdoor Fragment类将加载完全正常。但当我在“户外”再次点击滑块菜单时,室外片段崩溃了。
这是我的错误
10-09 16:46:17.914: E/Fragment(15011): Fragment not null
10-09 16:46:17.964: E/AndroidRuntime(15011): FATAL EXCEPTION: main
10-09 16:46:17.964: E/AndroidRuntime(15011): Process: me.chihao.maes, PID: 15011
10-09 16:46:17.964: E/AndroidRuntime(15011): android.view.InflateException: Binary XML file line #7: Error inflating class fragment
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-09 16:46:17.964: E/AndroidRuntime(15011): at me.chihao.maes.OutdoorFragment.onCreateView(OutdoorFragment.java:84)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:450)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.os.Handler.handleCallback(Handler.java:733)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.os.Handler.dispatchMessage(Handler.java:95)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.os.Looper.loop(Looper.java:212)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.app.ActivityThread.main(ActivityThread.java:5151)
10-09 16:46:17.964: E/AndroidRuntime(15011): at java.lang.reflect.Method.invokeNative(Native Method)
10-09 16:46:17.964: E/AndroidRuntime(15011): at java.lang.reflect.Method.invoke(Method.java:515)
10-09 16:46:17.964: E/AndroidRuntime(15011): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-09 16:46:17.964: E/AndroidRuntime(15011): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
10-09 16:46:17.964: E/AndroidRuntime(15011): at dalvik.system.NativeStart.main(Native Method)
10-09 16:46:17.964: E/AndroidRuntime(15011): Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f08003b, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.app.Activity.onCreateView(Activity.java:4791)
10-09 16:46:17.964: E/AndroidRuntime(15011): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
10-09 16:46:17.964: E/AndroidRuntime(15011): ... 19 more
我不确定为什么会发生这种情况,因为我按照在线教程进行了操作。
这是我的户外片段课程:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_outdoor, container,
false);
context = this.getActivity();
hashmarkers = new HashMap<String, String>();
hashImages = new HashMap<String, String>();
refresh = (Button) rootView.findViewById(R.id.refresh);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
listName.clear();
listIllness.clear();
listIC.clear();
listElderlyimage.clear();
listArduinomac.clear();
listLat.clear();
listLong.clear();
googleMap.getUiSettings().setZoomGesturesEnabled(true);
googleMap.getUiSettings().setRotateGesturesEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
googleMap.setMyLocationEnabled(true);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
1.3000, 103.8000), 10.0f));
zone = Act_Main.getzone();
ip = Act_Main.getip();
URL_gps_location = "http://" + ip + "/droidlogin/gps_location.php";
post4 = new Httppostaux();
googleMap.setInfoWindowAdapter(new InfoWindowAdapterMarker(context));
googleMap.clear();
new asyncGPS().execute(zone);
refresh.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
googleMap.clear();
// TODO Auto-generated method stub
listName.clear();
listIllness.clear();
listIC.clear();
listElderlyimage.clear();
listArduinomac.clear();
listLat.clear();
listLong.clear();
new asyncGPS().execute(zone);
}
});
return rootView;
}
并且你需要检查我的fragment_outdoor.xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/refresh" />
<Button
android:id="@+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="Refresh" />
答案 0 :(得分:0)
您需要显示所有代码,尤其是那些切换标签的代码。但是你收到错误:
Duplicate id 0x7f08003b, tag null, or parent id 0xffffffff with another fragment
for com.google.android.gms.maps.MapFragment
表示您尝试将包含此片段的视图添加到已包含该视图的根视图中,从而导致id冲突。您可能希望直接从代码中启动和添加映射片段,而不是在XML代码中引用它。