未找到Google Maps API密钥

时间:2013-02-25 16:37:41

标签: android google-maps google-maps-api-2

尝试使用适用于Android的Google Maps v2 API,它一直告诉我找不到我的API密钥。我已尝试过其他帖子的建议,但没有任何效果。我刚刚创建了一个新的API密钥来验证密钥没有缺陷。我还使用了Google设置文档中指定的代码,仍然无法使其工作。以下是所有相关文件。感谢。

02-25 11:16:30.890: E/AndroidRuntime(2260): FATAL EXCEPTION: main
02-25 11:16:30.890: E/AndroidRuntime(2260): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.echofriendly/com.example.echofriendly.MainMapFragment}:     android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.os.Looper.loop(Looper.java:137)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.ActivityThread.main(ActivityThread.java:4745)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at java.lang.reflect.Method.invokeNative(Native Method)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at java.lang.reflect.Method.invoke(Method.java:511)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at dalvik.system.NativeStart.main(Native Method)  
02-25 11:16:30.890: E/AndroidRuntime(2260): Caused by: android.view.InflateException: Binary XML  file line #2: Error inflating class fragment
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.Activity.setContentView(Activity.java:1867)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.example.echofriendly.MainMapFragment.onCreate(MainMapFragment.java:11)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.Activity.performCreate(Activity.java:5008)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
02-25 11:16:30.890: E/AndroidRuntime(2260):     ... 11 more
02-25 11:16:30.890: E/AndroidRuntime(2260): Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
02-25 11:16:30.890: E/AndroidRuntime(2260):     at maps.y.z.a(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at maps.y.z.a(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at maps.y.z.a(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at maps.y.ae.a(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at maps.y.bu.a(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at maps.y.p.onCreateView(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.os.Binder.transact(Binder.java:326)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.google.android.gms.maps.MapFragment$b.onCreateView(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.google.android.gms.internal.d$4.a(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.google.android.gms.internal.d.a(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.google.android.gms.internal.d.onCreateView(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:807)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1013)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1112)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.app.Activity.onCreateView(Activity.java:4664)
02-25 11:16:30.890: E/AndroidRuntime(2260):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)

的活动:

package com.example.echofriendly;

import android.app.Activity;
import android.os.Bundle;

 public class MainMapFragment extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map_fragment);

}

}

XML:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment" />

清单:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />


<permission
    android:name="com.example.echofriendly.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.example.echofriendly.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />


----
 <meta_data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="xxxxxx"/>

</application>

1 个答案:

答案 0 :(得分:2)

错误消息中的有用提示说:

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

您的代码说:

<meta_data android:name="com.google.android.maps.v2.API_KEY"
           android:value="xxxxxx"/>

发现差异?将您的_更改为-