【问题标题】:android.view.InflateException, Error inflating fragment classandroid.view.InflateException,错误膨胀片段类
【发布时间】:2015-10-02 14:34:05
【问题描述】:

我想实现一个具有 MapView 和 NavigationView 的布局,下面是我按照this 教程尝试的。我收到此错误android.view.InflateException: Binary XML file line #43: Error inflating class fragmen 出了什么问题?

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".ShopsCatalogActivityUsingMapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!--toolbar-->
        <include
            android:id="@+id/tool_bar"
            layout="@layout/tool_bar">

        </include>

        <!--map-->
        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <!--map-->
            <fragment xmlns:map="http://schemas.android.com/apk/res-auto"
                xmlns:tools="http://schemas.android.com/tools"
                android:id="@+id/map"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".CustomInfo" />
        </FrameLayout>
    </LinearLayout>

    <!--navigation drawer-->
    <android.support.design.widget.NavigationView
        android:id="@+id/my_navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_view_header"
        app:menu="@menu/navigation_drawer_menu" />

</android.support.v4.widget.DrawerLayout>

第 43 行是包含地图的片段

【问题讨论】:

  • 这是您的整个 XML 文件吗?那些需要包装在抽屉布局中
  • 贴出整个布局文件,#43是哪一行?

标签: android android-fragments fragment android-inflate


【解决方案1】:

&lt;fragment

改变

android:name="com.google.android.gms.maps.SupportMapFragment"

class = "com.google.android.gms.maps.SupportMapFragment"

希望这会有所帮助!

【讨论】:

  • 好的,检查你是否像这样扩展片段:import android.support.v4.app.Fragment;
【解决方案2】:

问题是我忘记将谷歌地图 API 密钥添加到清单文件中。我补充说:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

【讨论】:

    猜你喜欢
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多