大家好!我有一个问题,我的应用程序只是在启动时崩溃,因为它无法找到我的API密钥,似乎......我想要实现的是向我的活动添加一个地图片段,但它找不到我的API键。我只是想知道你们中有些人是否遇到过这个问题并能发现我正在犯的错误,因为我不能这样做?
我提供了错误消息,我的AndroidManifest.xml以及我尝试切换到地图片段的方法。
echo file_get_contents("https://www.this-domain.com/logo.gif");
//...failed to open stream:HTTP request failed! HTTP/1.1 404 Not Found...
//However both of the following work absolutely fine:
echo file_get_contents("https://www.google.com/");
echo file_get_contents("/home/user/domains/this-domain.com/private_html/media/logospin.gif");
这是我的AndroidManifest.xml
java.lang.RuntimeException: Unable to start activity ComponentInfo{no.premer.mytravels/no.premer.mytravels.MainActivity}: 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 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2407)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5321)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
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:380)
at com.google.android.gms.maps.internal.zzc$zza$zza.zzr(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$zzb.zzvu(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onCreate(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreate(Unknown Source)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1766)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:917)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
at android.app.Activity.performStart(Activity.java:5949)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2407)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5321)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
<?xml version="1.0" encoding="utf-8"?>
这是我添加地图代码的地方。
<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" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!--
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" >
<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=".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>
</application>