2014-03-26 41 views
0

我一直在學習本教程[http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/]的Android GPS 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 
+0

你在模擬器中試試嗎? – Giridharan

+0

請上傳您的AndroidManifest.xml文件 – Kedarnath

回答

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 

添加谷歌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> 

這是因爲谷歌最新的播放服務,需要一個版本的名稱,這是使用<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> 
+0

的代碼<元數據 機器人:名字= 「com.google.android.maps.v2.API_KEY」 機器人:V *我的鑰匙*」 /> 我已經有應用程序 – user3247335

+0

中的元數據還添加了另一個''標籤,根據我的回答,這是becoz提供在manifest.xml中提及版本值所需的最新服務 –

+0

優秀的工作表單謝謝 – user3247335