【问题标题】:FATAL EXCEPTION: main, Error inflating class fragment, android.view.InflateException致命异常:主要,膨胀类片段时出错,android.view.InflateException
【发布时间】:2020-02-06 15:16:54
【问题描述】:

我正在尝试制作地图应用程序。使用按钮链接到 MapActivity 类,但当我按下按钮时应用程序立即崩溃。请告知,如果需要更多信息来解决错误,请随时向我提出要求。

MapActivity.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map); //<-- logcat points at this line

    }

活动地图

<androidx.coordinatorlayout.widget.CoordinatorLayout
    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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapActivity">



    <include layout="@layout/content_map" /> //<-- this is line 12



</androidx.coordinatorlayout.widget.CoordinatorLayout>

content_map.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MapActivity"
    tools:showIn="@layout/activity_map"*>


    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.skyfishjy.library.RippleBackground
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/ripple_bg"
        app:rb_color="#0099CC"
        app:rb_radius="32dp"
        app:rb_rippleAmount="4"
        app:rb_duration="3000"
        app:rb_scale="6">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:translationY="-18dp"
            android:src="@drawable/ic_placeholder"/>
    </com.skyfishjy.library.RippleBackground>
    <com.mancj.materialsearchbar.MaterialSearchBar
        style="@style/MaterialSearchBarLight"
        app:mt_speechMode="false"
        app:mt_hint="Search a place"
        app:mt_maxSuggestionsCount="10"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/searchBar"
        android:layout_margin="16dp"
        app:mt_navIconEnabled="true"
        android:elevation="5dp"
        android:outlineProvider="bounds"
        app:mt_placeholder="Search a place"/>

    <Button
        android:id="@+id/btn_find"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Find Restaurants"
        android:textColor="#FFFFFF"
        android:background="@color/colorPrimary"
        android:layout_margin="16dp"
        android:textStyle="bold"/>

</RelativeLayout>

Logcat Continue from logcat1

【问题讨论】:

  • 构建 gradle 依赖项{ implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0' }
  • content_map,相对布局在开始标记处有一个 *。
  • 我认为我在发布问题时不小心添加了它,对不起,我将编辑帖子
  • 确切的异常消息是什么?
  • java.lang.RuntimeException:无法启动活动 ComponentInfo{com.example.superapp/com.example.superapp.MapActivity}:android.view.InflateException:com 中的二进制 XML 文件第 12 行。 example.superapp:layout/activity_map:com.example.superapp:layout/content_map 中的二进制 XML 文件第 12 行:膨胀类片段时出错

标签: java android fatal-error


【解决方案1】:

根据您的完整堆栈跟踪,您没有在清单中输入 API 密钥。将以下内容放入清单中,&lt;application&gt; 标记下。

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value=" your key here" />

按照此处的指南设置 API 密钥

https://developers.google.com/maps/documentation/android-sdk/get-api-key

【讨论】:

  • 非常感谢,我没有意识到这一点。我在我的字符串文件中附加了我的 api 密钥,但没有在元数据中。
猜你喜欢
  • 1970-01-01
  • 2023-03-05
  • 1970-01-01
  • 1970-01-01
  • 2020-07-28
  • 1970-01-01
  • 1970-01-01
  • 2013-11-21
  • 1970-01-01
相关资源
最近更新 更多