嘿,我每个人都按照这个教程http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/在Android中谷歌地图但我的应用程序已经崩溃了什么我不能理解的问题请帮我解决这个问题...
这是
07-20 15:22:22.758: D/AndroidRuntime(1260): Shutting down VM
07-20 15:22:22.758: W/dalvikvm(1260): threadid=1: thread exiting with uncaught exception (group=0xb3afbba8)
07-20 15:22:22.788: E/AndroidRuntime(1260): FATAL EXCEPTION: main
07-20 15:22:22.788: E/AndroidRuntime(1260): Process: com.example.googlemap, PID: 1260
07-20 15:22:22.788: E/AndroidRuntime(1260): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.os.Handler.dispatchMessage(Handler.java:102)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.os.Looper.loop(Looper.java:136)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-20 15:22:22.788: E/AndroidRuntime(1260): at java.lang.reflect.Method.invokeNative(Native Method)
07-20 15:22:22.788: E/AndroidRuntime(1260): at java.lang.reflect.Method.invoke(Method.java:515)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-20 15:22:22.788: E/AndroidRuntime(1260): at dalvik.system.NativeStart.main(Native Method)
07-20 15:22:22.788: E/AndroidRuntime(1260): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.app.Activity.setContentView(Activity.java:1929)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.example.googlemap.MainActivity.onCreate(MainActivity.java:18)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.app.Activity.performCreate(Activity.java:5231)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
07-20 15:22:22.788: E/AndroidRuntime(1260): ... 11 more
07-20 15:22:22.788: E/AndroidRuntime(1260): 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" />
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.google.android.gms.common.GooglePlayServicesUtil.x(Unknown Source)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.google.android.gms.maps.internal.u.F(Unknown Source)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.google.android.gms.maps.internal.u.E(Unknown Source)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.google.android.gms.maps.MapFragment$b.ju(Unknown Source)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.google.android.gms.dynamic.a.a(Unknown Source)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
07-20 15:22:22.788: E/AndroidRuntime(1260): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.app.Activity.onCreateView(Activity.java:4785)
07-20 15:22:22.788: E/AndroidRuntime(1260): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
07-20 15:22:22.788: E/AndroidRuntime(1260): ... 24 more
这是我的清单文件......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemap"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.googlemap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.googlemap.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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>
</application>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API key" />
</manifest>
答案 0 :(得分:3)
您需要将这些行放在Android Manifest文件的应用程序标记中,但是您将其包含在应用程序标记之后。此外,您还需要将日志猫清楚地告诉
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
见这里:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemap"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.googlemap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.googlemap.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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="API key" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application>
</manifest>
如果您想在AVD中获取地图,请参阅我在其他帖子中回答的here。
答案 1 :(得分:1)
添加此
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<application ...>
中的像这样
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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.gms.version" android:value="@integer/google_play_services_version" />
</application>
答案 2 :(得分:1)
你在AVD中运行应用程序,Google Play服务无法在AVD中运行..,请连接您的Android手机并在手机内运行应用程序..,我有同样的错误
尝试以这种方式创建一个Google AI类型的模拟器,并将Project build Target更改为Google Api ..如下所示....
好的,在尝试了一些事情之后,事实证明我有一个最后一个选项没有被正确检查,这在教程中没有提到..
而不是Android 4.4.2作为项目构建目标&amp;模拟器目标,我已经选择了Google API 4.4.2。现在我不再收到Google Play服务的错误。
我确实得到了NullPointerException,但至少我可以继续..;)
编辑:修复了NullPointerException并修改了原始帖子中的代码。一切正常,我希望这篇文章可以帮助其他人使用Android模拟器使用Google Play服务登录时遇到相同(或其他)错误。