全部:
我是安卓的新手。现在我要运行一个 Android Maps V2 项目。我按照https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw中的描述一步一步地进行操作,失败并尝试了很多次,但我不断遇到以下问题:
02-03 01:48:48.783: E/AndroidRuntime(11547): FATAL EXCEPTION: main
02-03 01:48:48.783: E/AndroidRuntime(11547): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemapdemo/com.example.googlemapdemo.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.ActivityThread.access$600(ActivityThread.java:127)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.os.Looper.loop(Looper.java:137)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.ActivityThread.main(ActivityThread.java:4507)
02-03 01:48:48.783: E/AndroidRuntime(11547): at java.lang.reflect.Method.invokeNative(Native Method)
02-03 01:48:48.783: E/AndroidRuntime(11547): at java.lang.reflect.Method.invoke(Method.java:511)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
02-03 01:48:48.783: E/AndroidRuntime(11547): at dalvik.system.NativeStart.main(Native Method)
02-03 01:48:48.783: E/AndroidRuntime(11547): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:271)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.Activity.setContentView(Activity.java:1835)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.example.googlemapdemo.MainActivity.onCreate(MainActivity.java:18)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.Activity.performCreate(Activity.java:4465)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
02-03 01:48:48.783: E/AndroidRuntime(11547): ... 11 more
02-03 01:48:48.783: E/AndroidRuntime(11547): 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-03 01:48:48.783: E/AndroidRuntime(11547): at maps.y.z.a(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at maps.y.z.a(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at maps.y.z.a(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at maps.y.ae.a(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at maps.y.bu.a(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at maps.y.p.onCreateView(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.os.Binder.transact(Binder.java:297)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.google.android.gms.maps.MapFragment$b.onCreateView(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.google.android.gms.internal.d$4.a(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.google.android.gms.internal.d.a(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.google.android.gms.internal.d.onCreateView(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:806)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1010)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1108)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.app.Activity.onCreateView(Activity.java:4243)
02-03 01:48:48.783: E/AndroidRuntime(11547): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
02-03 01:48:48.783: E/AndroidRuntime(11547): ... 21 more
这是我的项目,它非常基本且简短。也许有一个很常见的错误,但如果你能指出我,我将非常感激!
活动主.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
AndroidMenifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.googlemapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.googlemapdemo.permission.MAPS_RECEIVE"/>
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!-- End of copy. -->
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.googlemapdemo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxx"/>
</activity>
</application>
</manifest>
MainActivity.java:
package com.example.googlemapdemo;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private GoogleMap mGMap;
}