我是 Stackoverflow 的新手。我在新的 Google Maps API v2 上显示地图时遇到问题。我完成了此页面https://developers.google.com/maps/documentation/android/start?hl=pl的所有步骤以及一些教程,但我无法显示地图。当我运行我的应用程序时,在模拟器上只显示放大控件,其余屏幕是白色的,我无法在我的真实设备上打开它(HTC Wildfire S-android 2.3.5)。我也将 google_play_service_lib 添加到我的项目中。我在很多页面和很多教程中都在寻找我的问题的答案,但我没有找到!请帮我!
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.adrianspora.googlemaptest"
android:versionCode="1"
android:versionName="1.0" >
<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.adrianspora.googlemaptest.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="AIzaSyD6r1gse4Jx4sTrCECvLQQwgxLJikHm4Ow"/>
</application>
<permission
android:name="com.adrianspora.googlemaptest.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.adrianspora.googlemaptest.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<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_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
</manifest>
MainActivity的代码:
package com.adrianspora.googlemaptest;
import com.google.android.gms.maps.MapFragment;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
它是主要布局的代码:
<LinearLayout 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" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
LogCat 中有一个日志显示列表:
06-22 14:51:44.897: D/AndroidRuntime(1092): Shutting down VM
06-22 14:51:44.927: W/dalvikvm(1092): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-22 14:51:44.996: E/AndroidRuntime(1092): FATAL EXCEPTION: main
06-22 14:51:44.996: E/AndroidRuntime(1092): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.adrianspora.googlemaptest/com.adrianspora.googlemaptest.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.os.Handler.dispatchMessage(Handler.java:99)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.os.Looper.loop(Looper.java:137)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-22 14:51:44.996: E/AndroidRuntime(1092): at java.lang.reflect.Method.invokeNative(Native Method)
06-22 14:51:44.996: E/AndroidRuntime(1092): at java.lang.reflect.Method.invoke(Method.java:511)
06-22 14:51:44.996: E/AndroidRuntime(1092): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-22 14:51:44.996: E/AndroidRuntime(1092): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-22 14:51:44.996: E/AndroidRuntime(1092): at dalvik.system.NativeStart.main(Native Method)
06-22 14:51:44.996: E/AndroidRuntime(1092): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-22 14:51:44.996: E/AndroidRuntime(1092): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.Activity.setContentView(Activity.java:1881)
06-22 14:51:44.996: E/AndroidRuntime(1092): at com.adrianspora.googlemaptest.MainActivity.onCreate(MainActivity.java:15)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.Activity.performCreate(Activity.java:5104)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-22 14:51:44.996: E/AndroidRuntime(1092): ... 11 more
06-22 14:51:44.996: E/AndroidRuntime(1092): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
06-22 14:51:44.996: E/AndroidRuntime(1092): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
06-22 14:51:44.996: E/AndroidRuntime(1092): ... 21 more
06-22 15:00:25.848: D/dalvikvm(1273): GC_CONCURRENT freed 256K, 15% free 2600K/3032K, paused 85ms+37ms, total 193ms
06-22 15:00:26.236: D/dalvikvm(1273): GC_CONCURRENT freed 272K, 14% free 2742K/3188K, paused 72ms+5ms, total 116ms
06-22 15:00:26.267: E/Google Maps Android API(1273): Google Maps Android API v2 only supports devices with OpenGL ES 2.0 and above
06-22 15:00:26.487: D/dalvikvm(1273): GC_FOR_ALLOC freed 152K, 11% free 2895K/3224K, paused 40ms, total 41ms
06-22 15:00:26.747: D/dalvikvm(1273): GC_CONCURRENT freed 85K, 8% free 3271K/3540K, paused 22ms+87ms, total 155ms
06-22 15:00:27.057: D/libEGL(1273): Emulator without GPU support detected. Fallback to software renderer.
06-22 15:00:27.087: I/Choreographer(1273): Skipped 56 frames! The application may be doing too much work on its main thread.
06-22 15:00:27.127: D/libEGL(1273): loaded /system/lib/egl/libGLES_android.so
06-22 15:00:27.188: D/gralloc_goldfish(1273): Emulator without GPU emulation detected.
06-22 15:00:28.117: D/dalvikvm(1273): GC_CONCURRENT freed 266K, 12% free 3470K/3912K, paused 36ms+7ms, total 128ms
06-22 15:00:28.117: D/dalvikvm(1273): WAIT_FOR_CONCURRENT_GC blocked 79ms
06-22 15:00:28.216: D/dalvikvm(1273): GC_FOR_ALLOC freed 435K, 18% free 3340K/4044K, paused 45ms, total 51ms
06-22 15:00:28.348: D/dalvikvm(1273): GC_CONCURRENT freed 326K, 15% free 3470K/4044K, paused 15ms+8ms, total 69ms
06-22 15:00:28.348: D/dalvikvm(1273): WAIT_FOR_CONCURRENT_GC blocked 45ms
06-22 15:00:28.557: D/dalvikvm(1273): GC_CONCURRENT freed 551K, 19% free 3399K/4152K, paused 21ms+26ms, total 113ms
06-22 15:00:36.126: E/Google Maps Android API(1273): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
06-22 15:00:36.136: E/Google Maps Android API(1273): Ensure that the following correspond to what is in the API Console: Package Name: com.adrianspora.googlemaptest, API Key: AIzaSyD6r1gse4Jx4sTrCECvLQQwgxLJikHm4Ow, Certificate Fingerprint: 1D915CBBCDEBB8CECC48371ED32EE0D5CA5DB443
06-22 15:14:09.636: E/Trace(1502): error opening trace file: No such file or directory (2)
06-22 15:14:11.196: D/dalvikvm(1502): GC_CONCURRENT freed 230K, 14% free 2599K/3004K, paused 124ms+91ms, total 328ms
06-22 15:14:11.386: E/Google Maps Android API(1502): Google Maps Android API v2 only supports devices with OpenGL ES 2.0 and above
06-22 15:14:11.626: D/dalvikvm(1502): GC_CONCURRENT freed 264K, 14% free 2789K/3228K, paused 73ms+86ms, total 226ms
06-22 15:14:11.796: D/dalvikvm(1502): GC_FOR_ALLOC freed 119K, 12% free 2913K/3280K, paused 37ms, total 38ms
06-22 15:14:12.106: D/dalvikvm(1502): GC_CONCURRENT freed 64K, 8% free 3288K/3556K, paused 71ms+73ms, total 208ms
06-22 15:14:12.477: D/libEGL(1502): Emulator without GPU support detected. Fallback to software renderer.
06-22 15:14:12.496: D/libEGL(1502): loaded /system/lib/egl/libGLES_android.so
06-22 15:14:12.536: I/Choreographer(1502): Skipped 69 frames! The application may be doing too much work on its main thread.
06-22 15:14:12.656: D/gralloc_goldfish(1502): Emulator without GPU emulation detected.
06-22 15:14:13.307: D/dalvikvm(1502): GC_CONCURRENT freed 332K, 14% free 3358K/3868K, paused 143ms+137ms, total 477ms
06-22 15:14:13.307: D/dalvikvm(1502): WAIT_FOR_CONCURRENT_GC blocked 322ms
06-22 15:14:13.766: D/dalvikvm(1502): GC_CONCURRENT freed 365K, 15% free 3471K/4040K, paused 6ms+7ms, total 296ms
06-22 15:14:13.766: D/dalvikvm(1502): WAIT_FOR_CONCURRENT_GC blocked 97ms
06-22 15:14:13.866: D/dalvikvm(1502): GC_FOR_ALLOC freed 434K, 18% free 3342K/4040K, paused 39ms, total 46ms
06-22 15:14:14.056: D/dalvikvm(1502): GC_CONCURRENT freed 433K, 16% free 3400K/4040K, paused 12ms+27ms, total 109ms
06-22 15:14:18.076: E/Google Maps Android API(1502): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
06-22 15:14:18.076: E/Google Maps Android API(1502): Ensure that the following correspond to what is in the API Console: Package Name: com.adrianspora.googlemaptest, API Key: AIzaSyD6r1gse4Jx4sTrCECvLQQwgxLJikHm4Ow, Certificate Fingerprint: 1D915CBBCDEBB8CECC48371ED32EE0D5CA5DB443
06-22 15:14:23.066: I/Choreographer(1502): Skipped 96 frames! The application may be doing too much work on its main thread.