尝试使用适用于 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>