gpt4 book ai didi

android - Google map 错误 - Android 应用 ¦¦ v2

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:36:42 25 4
gpt4 key购买 nike

我正在尝试将 map 添加到我在 Android 应用程序上的布局,但我得到以下代码:

06-16 20:51:06.142  17581-17581/wk.gon250.dublinbike E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{wk.gon250.dublinbike/wk.gon250.dublinbike.StationDetailsActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2266)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at wk.gon250.dublinbike.StationDetailsActivity.onCreate(StationDetailsActivity.java:38)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
            at android.app.ActivityThread.access$600(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:5225)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
            at dalvik.system.NativeStart.main(Native Method)
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
at com.google.maps.api.android.lib6.d.fk.a(Unknown Source)
at com.google.maps.api.android.lib6.a.g.a(Unknown Source)
at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
at com.google.android.gms.maps.internal.i.onTransact(SourceFile:62)
at android.os.Binder.transact(Binder.java:347)
at com.google.android.gms.maps.internal.zzc$zza$zza.zzr(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.zzvu(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.Activity.onCreateView(Activity.java:4745)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at wk.gon250.dublinbike.StationDetailsActivity.onCreate(StationDetailsActivity.java:38)
            at android.app.Activity.performCreate(Activity.java:5133)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
            at android.app.ActivityThread.access$600(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:5225)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
            at dalvik.system.NativeStart.main(Native Method)

Note: Check that is in the element of AndroidManifest.xml

我已经尝试更改 api key 但我仍然遇到相同的错误。

知道如何解决这个问题吗?

看看下面我的代码:

Android list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wk.gon250.dublinbike" >

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<meta-data
android:name="com.google.maps.v2.API_KEY"
android:value="my_api_key"
/>

<activity
android:name=".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>
<activity
android:name=".StationDetailsActivity"
android:label="@string/title_activity_station_details" >
</activity>
</application>

</manifest>

布局

<FrameLayout
android:id="@+id/mapFrame"
android:layout_width="match_parent"
android:layout_height="@dimen/map_size" >

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

<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/ic_1"
android:onClick="expandB"
android:src="@drawable/ic_2" />
</FrameLayout>

感谢您的宝贵时间!

最佳答案

你的错误是这样说的

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

我认为您应该为您的项目添加 API key 。您必须添加调试 api key 。

首先在 values 目录中创建 xml 文件。将其命名为 google_maps_api。添加此代码段:

<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
YOUR API KEY HERE!!!
</string>

您的 list 必须如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="company.mapapp">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:logo="@drawable/male80">
<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="@string/google_maps_key" />


<activity
android:name="company.mapapp.SplashActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


<activity android:name=".MainActivity" />



</application>

</manifest>

关于android - Google map 错误 - Android 应用 ¦¦ v2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30876984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com