android.view.InflateException:二进制XML文件行#1:错误膨胀类片段

时间:2014-02-02 16:32:40

标签: android android-fragments


我有以下问题: 我有一个带有两个片段的FragmentActivity。其中一个是MapFragment。如果我第一次完全运行时用地图打开片段。但是,当我导航回第一个片段,然后再次使用地图打开片段时,应用程序崩溃并显示以下LogCat输出:

    02-02 17:01:28.589: E/AndroidRuntime(13587): FATAL EXCEPTION: main
    02-02 17:01:28.589: E/AndroidRuntime(13587): Process: de.simeon.maps, PID: 13587
    02-02 17:01:28.589: E/AndroidRuntime(13587): android.view.InflateException: Binary XML file line #1: Error inflating class fragment
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:547)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.view.LayoutInflater.inflate(Native Method)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at de.simeon.maps.MainActivity$Map.onCreateView(MainActivity.java:141)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.os.Handler.handleCallback(Handler.java:733)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.os.Handler.dispatchMessage(Handler.java:95)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.os.Looper.loop(Looper.java:136)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.app.ActivityThread.main(ActivityThread.java:5017)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at java.lang.reflect.Method.invokeNative(Native Method)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at java.lang.reflect.Method.invoke(Method.java:515)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at dalvik.system.NativeStart.main(Native Method)
    02-02 17:01:28.589: E/AndroidRuntime(13587): Caused by: java.lang.IllegalArgumentException: Binary XML file line #1: Duplicate id 0x7f050006, tag null, or parent id 0x7f050005 with another fragment for com.google.android.gms.maps.MapFragment
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.app.Activity.onCreateView(Activity.java:4791)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
    02-02 17:01:28.589: E/AndroidRuntime(13587):    ... 22 more


My Fragment with the map:

    public static class Map extends Fragment {

    public Map() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_map, container, false);


        return rootView;
    }
}


我的fragment_map.xml:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.MapFragment"
    tools:context=".MainActivity$Map"
    tools:ignore="MergeRootFrame"/>


我的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.simeon.maps"
    android:versionCode="1"
    android:versionName="1.0" >

    <permission 
               android:name="example.gps.permission.MAPS_RECEIVE" 
               android:protectionLevel="signature"></permission>

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyD6KQk5r39QnU_M5JOJwA3klu7jsXMD7Jk" />

        <activity
            android:name="de.simeon.maps.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

你能帮帮我吗?

2 个答案:

答案 0 :(得分:4)

如果您使用的是FragmentActivity,则表示您正在使用Android支持包的片段后端口。在这种情况下,您需要在布局中使用SupportMapFragment,而不是MapFragment

另请注意,您正在尝试将片段放入片段中。虽然这是可能的,但它不太可能是你想要的。

答案 1 :(得分:0)

必须仅在google_maps_api.xml中指定API密钥。 在清单元数据标记中,只需将键的值作为资源字符串@ string / google_maps_key。

希望它有帮助..!