我创建了一个api。所有步骤都已完成。这张地图很有用。我不记得为什么我删除谷歌播放服务库并再次加载。随后发生此错误。
的manifest.xml;
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<meta-data
android:name="com.google.android.gms.v2.API_KEY"
android:value= my api key />
google_map.xml;
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class = "com.google.android.gms.maps.SupportMapFragment" />
Log cat;
12-09 11:43:34.092: E/AndroidRuntime(28745): FATAL EXCEPTION: main
12-09 11:43:34.092: E/AndroidRuntime(28745): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cryptodlp/com.example.cryptodlp.GoogleMapFragment}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.app.ActivityThread.access$700(ActivityThread.java:134)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.os.Handler.dispatchMessage(Handler.java:99)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.os.Looper.loop(Looper.java:137)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.app.ActivityThread.main(ActivityThread.java:4867)
12-09 11:43:34.092: E/AndroidRuntime(28745): at java.lang.reflect.Method.invokeNative(Native Method)
12-09 11:43:34.092: E/AndroidRuntime(28745): at java.lang.reflect.Method.invoke(Method.java:511)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
12-09 11:43:34.092: E/AndroidRuntime(28745): at dalvik.system.NativeStart.main(Native Method)
12-09 11:43:34.092: E/AndroidRuntime(28745): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.app.Activity.setContentView(Activity.java:1901)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.example.cryptodlp.GoogleMapFragment.onCreate(GoogleMapFragment.java:35)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.app.Activity.performCreate(Activity.java:5047)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
12-09 11:43:34.092: E/AndroidRuntime(28745): ... 11 more
12-09 11:43:34.092: E/AndroidRuntime(28745): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. 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" />
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.google.android.gms.maps.internal.q.v(Unknown Source)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.google.android.gms.maps.internal.q.u(Unknown Source)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.google.android.gms.dynamic.a.a(Unknown Source)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
12-09 11:43:34.092: E/AndroidRuntime(28745): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
12-09 11:43:34.092: E/AndroidRuntime(28745): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
12-09 11:43:34.092: E/AndroidRuntime(28745): ... 21 more
答案 0 :(得分:1)
在xml中添加:
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
在你的清单文件中添加:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
希望这有帮助。