Android GPS V2教程问题 - 谷歌地图

时间:2014-03-26 03:57:21

标签: java android api gps maps

我一直在使用本教程[http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/]

其GPS地图位置应用程序,可获取您的位置或附近位置。我和其他许多人已经对此进行了测试,似乎有一个错误,因为应用程序崩溃了。 我更改了SHA1指纹和Google API密钥。 代码中没有错误,我已经导入了Google Play商店。

有没有人对此有任何想法,我查看了网站上的评论,并且分配用户也遇到了同样的问题。 这是LogCat:

03-26 03:43:53.835: W/dalvikvm(15048): threadid=1: thread exiting with uncaught exception (group=0x42014700)
03-26 03:43:53.845: E/AndroidRuntime(15048): FATAL EXCEPTION: main
03-26 03:43:53.845: E/AndroidRuntime(15048): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.googlemapsv2/info.androidhive.googlemapsv2.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.os.Looper.loop(Looper.java:176)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.app.ActivityThread.main(ActivityThread.java:5419)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at java.lang.reflect.Method.invokeNative(Native Method)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at java.lang.reflect.Method.invoke(Method.java:525)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at dalvik.system.NativeStart.main(Native Method)
03-26 03:43:53.845: E/AndroidRuntime(15048): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.app.Activity.setContentView(Activity.java:1956)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at info.androidhive.googlemapsv2.MainActivity.onCreate(MainActivity.java:24)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.app.Activity.performCreate(Activity.java:5372)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
03-26 03:43:53.845: E/AndroidRuntime(15048):    ... 11 more
03-26 03:43:53.845: E/AndroidRuntime(15048): Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.maps.internal.q.B(Unknown Source)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.maps.internal.q.A(Unknown Source)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.maps.MapFragment$b.gW(Unknown Source)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.dynamic.a.a(Unknown Source)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.app.Activity.onCreateView(Activity.java:4965)
03-26 03:43:53.845: E/AndroidRuntime(15048):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
03-26 03:43:53.845: E/AndroidRuntime(15048):    ... 21 more

1 个答案:

答案 0 :(得分:2)

你的logcat清楚地说:

 Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
 03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
 03-26 03:43:53.845: E/AndroidRuntime(15048):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAv

将Google Play服务版本添加到您应用的清单

  

编辑应用程序的AndroidManifest.xml文件,然后添加   在元素中声明如下。这嵌入了版本   使用该应用编译的Google Play服务。

您只需将<meta-data>标记下的<application>添加到AndroidManifest.xml

....<application>
<meta-data android:name="com.google.android.gms.version"  
 android:value="@integer/google_play_services_version" />
</application>

这是因为最新的Google Play服务需要一个版本名称,使用<meta-data .. />内的AndroidManifest.xml来提及

构建您的 manifest.xml ,例如:

....<application>
  ..............
  <meta-data
  android:name="com.google.android.maps.v2.API_KEY"
  android:value="APIKEY" />

  <meta-data android:name="com.google.android.gms.version"  
  android:value="@integer/google_play_services_version" />

   </application>