我有这个布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/sat"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:onClick="myClickHandler"
android:padding="8dp"
android:text="@string/satellite" />
<Button
android:id="@+id/traffic"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.23"
android:onClick="myClickHandler"
android:padding="8dp"
android:text="@string/traffic" />
<Button
android:id="@+id/normal"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.24"
android:onClick="myClickHandler"
android:padding="8dp"
android:text="@string/normal" />
</LinearLayout>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.92" />
我需要在我的活动中调用膨胀来获取我的布局的所有视图。 我打电话给
LayoutInflater inflater = LayoutInflater.from(this);
View layout = inflater.inflate(res, null);
其中res是布局的ID,但有以下异常:
10-23 16:27:44.207: E/AndroidRuntime(12310): FATAL EXCEPTION: main
10-23 16:27:44.207: E/AndroidRuntime(12310): java.lang.RuntimeException: Unable to start activity ComponentInfo{it.unisa.microapp/it.unisa.microapp.activities.MapsLocationActivity}: android.view.InflateException: Binary XML file line #45: Error inflating class fragment
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.os.Looper.loop(Looper.java:137)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-23 16:27:44.207: E/AndroidRuntime(12310): at java.lang.reflect.Method.invokeNative(Native Method)
10-23 16:27:44.207: E/AndroidRuntime(12310): at java.lang.reflect.Method.invoke(Method.java:525)
10-23 16:27:44.207: E/AndroidRuntime(12310): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-23 16:27:44.207: E/AndroidRuntime(12310): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-23 16:27:44.207: E/AndroidRuntime(12310): at dalvik.system.NativeStart.main(Native Method)
10-23 16:27:44.207: E/AndroidRuntime(12310): Caused by: android.view.InflateException: Binary XML file line #45: Error inflating class fragment
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-23 16:27:44.207: E/AndroidRuntime(12310): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.app.Activity.setContentView(Activity.java:1895)
10-23 16:27:44.207: E/AndroidRuntime(12310): at it.unisa.microapp.activities.MAActivity.setAppView3(MAActivity.java:457)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.app.Activity.performCreate(Activity.java:5133)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-23 16:27:44.207: E/AndroidRuntime(12310): ... 11 more
10-23 16:27:44.207: E/AndroidRuntime(12310): Caused by: java.lang.IllegalArgumentException: Binary XML file line #45: Duplicate id 0x7f060011, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.app.Activity.onCreateView(Activity.java:4751)
10-23 16:27:44.207: E/AndroidRuntime(12310): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
我认为问题是我无法使用com.google.android.gms.maps.MapFragment对片段进行充气 我怎么解决?