Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android视图充气异常错误_Android_Google Maps_Android Fragments - Fatal编程技术网

Android视图充气异常错误

Android视图充气异常错误,android,google-maps,android-fragments,Android,Google Maps,Android Fragments,所以,我在android.view.InflateException上遇到了很多麻烦,我也不完全清楚为什么。它发生在我尝试加载Google地图片段时 如果您有任何关于此错误的想法/帮助,我们将不胜感激 Cocktails.xml <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:map="http:

所以,我在android.view.InflateException上遇到了很多麻烦,我也不完全清楚为什么。它发生在我尝试加载Google地图片段时

如果您有任何关于此错误的想法/帮助,我们将不胜感激

Cocktails.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="com.example.beng09715.restaurant_finder.Cocktails"
android:name="com.google.android.gms.maps.SupportMapFragment"/>

您的api密钥设置不正确,您可以在日志中看到:

Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
原因:java.lang.RuntimeException:未找到API密钥。检查一下那个在房间里

您将在开发人员控制台上的API密钥中使用以下SHA1指纹:


设置好API密钥后,将其放入
“@string/google\u maps\u key”
,即可完成所有设置。

发布XMLCocktails@Yazan添加了Cocktails.xmlGrand,它已经发挥了作用,关于谷歌地图的新工作方式,它会一直带你去谷歌地图应用程序,反对在我正在构建的应用程序中加载地图片段?@bdg太好了,很高兴它能为你工作!至于GoogleMapsV2 API的工作方式,你仍然可以在你的应用程序中使用地图,看起来你的代码应该可以做到这一点。有关更完整的示例,请参见此处:
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

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

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

    <activity
        android:name=".SplashScreen"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Home_screen"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar"></activity>
    <activity
        android:name=".Breakfast"
        android:label="@string/title_activity_breakfast"
        android:parentActivityName=".Home_screen"
        android:theme="@style/AppTheme.NoActionBar">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.beng09715.restaurant_finder.Home_screen" />

        <intent-filter>
            <action android:name="com.example.beng09715.restaurant_finder.Breakfast" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Menu"
        android:label="@string/app_name"></activity>
    <activity
        android:name=".Lunch"
        android:label="@string/app_name"></activity>
    <activity
        android:name=".AfternoonTea"
        android:label="@string/app_name"></activity>
    <activity
        android:name=".Dinner"
        android:label="@string/app_name"></activity>
    <activity
        android:name=".Cocktails"
        android:label="@string/title_activity_cocktails">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.beng09715.restaurant_finder.Home_screen" />
    </activity>

    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    -->

    <activity
        android:name=".MapViewer"
        android:label="@string/title_activity_map_viewer">
    </activity>
</application>
package com.example.beng09715.restaurant_finder;

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

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapViewer extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map_viewer);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="com.example.beng09715.restaurant_finder.Cocktails"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
    <meta-data
    android:name="com.google.android.maps.V2.API_KEY"
    android:value="@string/google_maps_key" />
    <meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_maps_key" />