【问题标题】:Add Google map to existing project has inflate exception将谷歌地图添加到现有项目有膨胀异常
【发布时间】:2018-08-04 06:18:49
【问题描述】:

我想显示现有应用的活动地图。我将地图片段添加到我的 xml 并获取 api 密钥但应用程序低于错误。我该如何解决这个问题?

我通过右键单击活动包并选择谷歌地图活动来添加地图 xml 和活动,但再次无法正常工作并出现错误。

我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    tools:context="com.co.KITIL.MapActivity"/>

<Button
    android:id="@+id/saveBtn"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:text="شروع کار"
    android:textSize="15sp"
    android:background="@color/blue"
    android:textColor="@android:color/white"/>
</LinearLayout>

我的活动:

package com.co.KITIL;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;


public class MapActivity extends FragmentActivity implements OnMapReadyCallback {

SupportMapFragment mapView;
GoogleMap googleMap;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    mapView=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
    mapView.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {

}
}

AndroidManifest:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIz-------------------------bcI" />

来自 debug.res.values 的 google_maps_api.xml;

<resources>

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AI-----------------bcI</string>

错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com..KITIL/com..KITIL.MapsActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                   at a
                                                Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
                                                Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class fragment
                                                Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: calling Fragment constructor caused an exception

【问题讨论】:

    标签: android google-maps runtime-error inflate-exception


    【解决方案1】:

    我在下面的链接中找到了我的解决方案:

    Google map not showing in android activity?

    我应该启用 google maps api,然后再次下载 google-services.json 并复制到解决方案中。

    【讨论】:

      猜你喜欢
      • 2018-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 2013-03-26
      • 1970-01-01
      • 2017-08-17
      相关资源
      最近更新 更多