我正在尝试按照本指南运行一个简单的地图:https ://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw
我在第 6 步和第 8 步迷路了。我应该在哪里放置“GooglePlayServices.util...”行和“GoogleMap map =”行?
我把它们都放在了最后的 androidmanifest.xml 文件中。
该程序运行但当我尝试在模拟器和我的android设备上打开它时它会崩溃。
这是我的代码。
Activity_Main.xml:
<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.SupportMapFragment"
/>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapexample"
android:versionCode="1"
android:versionName="1.0" >
<permission android:name="your_package_name.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="your_package_name.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<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_FINE_LOCATION"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mapexample.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCamZzoe1qpYwpNyqDNpAVw8wlrG1NBd60"/>
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
GoogleMap map = ((SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
</application>
</manifest>
这是 LogCat:
01-30 18:20:17.863: W/Trace(892): Unexpected value from nativeGetEnabledTags: 0
01-30 18:20:17.884: W/Trace(892): Unexpected value from nativeGetEnabledTags: 0
01-30 18:20:17.884: W/Trace(892): Unexpected value from nativeGetEnabledTags: 0
01-30 18:20:18.213: W/Trace(892): Unexpected value from nativeGetEnabledTags: 0
01-30 18:20:18.213: W/Trace(892): Unexpected value from nativeGetEnabledTags: 0
01-30 18:20:18.733: W/dalvikvm(892): VFY: unable to resolve static field 861
(MapAttrs) in Lcom/google/android/gms/R$styleable;
01-30 18:20:18.733: D/dalvikvm(892): VFY: replacing opcode 0x62 at 0x000e
01-30 18:20:18.754: D/AndroidRuntime(892): Shutting down VM
01-30 18:20:18.754: W/dalvikvm(892): threadid=1: thread exiting with uncaught
exception (group=0x40a70930)
01-30 18:20:18.763: E/AndroidRuntime(892): FATAL EXCEPTION: main
01-30 18:20:18.763: E/AndroidRuntime(892): java.lang.NoClassDefFoundError:
com.google.android.gms.R$styleable
01-30 18:20:18.763: E/AndroidRuntime(892): at
com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
01-30 18:20:18.763: E/AndroidRuntime(892): at
com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-30 18:20:18.763: E/AndroidRuntime(892): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.app.Activity.setContentView(Activity.java:1881)
01-30 18:20:18.763: E/AndroidRuntime(892): at
com.example.mapexample.MainActivity.onCreate(MainActivity.java:15)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.app.Activity.performCreate(Activity.java:5104)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.app.ActivityThread.access$600(ActivityThread.java:141)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.os.Handler.dispatchMessage(Handler.java:99)
01-30 18:20:18.763: E/AndroidRuntime(892): at android.os.Looper.loop(Looper.java:137)
01-30 18:20:18.763: E/AndroidRuntime(892): at
android.app.ActivityThread.main(ActivityThread.java:5039)
01-30 18:20:18.763: E/AndroidRuntime(892): at
java.lang.reflect.Method.invokeNative(Native Method)
01-30 18:20:18.763: E/AndroidRuntime(892): at
java.lang.reflect.Method.invoke(Method.java:511)
01-30 18:20:18.763: E/AndroidRuntime(892): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-30 18:20:18.763: E/AndroidRuntime(892): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-30 18:20:18.763: E/AndroidRuntime(892): at dalvik.system.NativeStart.main(Native
Method)