我今天的大项目是将我的应用程序迁移到新的 Google Maps API V2。但是,现在我遇到了一个错误,我似乎无法找到根本原因。
我的堆栈跟踪如下所示:
12-17 17:16:20.366: E/AndroidRuntime(3634): FATAL EXCEPTION: main
12-17 17:16:20.366: E/AndroidRuntime(3634): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobile.barwatch/com.mobile.barwatch.TestActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2088)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.ActivityThread.access$700(ActivityThread.java:139)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.os.Handler.dispatchMessage(Handler.java:99)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.os.Looper.loop(Looper.java:137)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.ActivityThread.main(ActivityThread.java:4918)
12-17 17:16:20.366: E/AndroidRuntime(3634): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 17:16:20.366: E/AndroidRuntime(3634): at java.lang.reflect.Method.invoke(Method.java:511)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
12-17 17:16:20.366: E/AndroidRuntime(3634): at dalvik.system.NativeStart.main(Native Method)
12-17 17:16:20.366: E/AndroidRuntime(3634): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:306)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.Activity.setContentView(Activity.java:1901)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.mobile.barwatch.TestActivity.onCreate(TestActivity.java:18)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.Activity.performCreate(Activity.java:5048)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2052)
12-17 17:16:20.366: E/AndroidRuntime(3634): ... 11 more
12-17 17:16:20.366: E/AndroidRuntime(3634): 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
12-17 17:16:20.366: E/AndroidRuntime(3634): at maps.y.z.a(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at maps.y.z.a(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at maps.y.z.a(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at maps.y.ae.a(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at maps.y.bu.a(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at maps.y.p.onCreateView(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.os.Binder.transact(Binder.java:326)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.google.android.gms.maps.MapFragment$b.onCreateView(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.google.android.gms.internal.d$4.a(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.google.android.gms.internal.d.a(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.google.android.gms.internal.d.onCreateView(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:807)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1013)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1112)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.app.Activity.onCreateView(Activity.java:4704)
12-17 17:16:20.366: E/AndroidRuntime(3634): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
12-17 17:16:20.366: E/AndroidRuntime(3634): ... 20 more
我的活动课程如下所示:
package com.mobile.barwatch;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gcm.GCMRegistrar;
import com.google.android.gms.common.*;
import com.mobile.barwatch.tasks.*;
import com.mobile.barwatch.models.Constants;
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_screen);
}
}
我的布局文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
我的清单的相关部分如下所示:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobile.barwatch"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="15" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission android:name="com.mobile.barwatch.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<permission android:name="com.mobile.barwatch.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.mobile.barwatch.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.mobile.barwatch.permission.C2D_MESSAGE" />
<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.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher_barwatch"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
....
<activity android:name="TestActivity"
android:label="@string/app_name">
</activity>
<meta-data android:name="com.google.android.maps.v2.xx"
android:value="xx"/>
</application>
</manifest>
我真的把我的头撞在墙上,所以任何帮助都将不胜感激。