Android 谷歌地图版本2不适用于片段
我不知道,我在装载映射版本2的清单、活动或xml中做错了什么 我发现了多个例外如果你看到我的简明日志Android 谷歌地图版本2不适用于片段,android,google-maps,Android,Google Maps,我不知道,我在装载映射版本2的清单、活动或xml中做错了什么 我发现了多个例外如果你看到我的简明日志 E/AndroidRuntime(16522): FATAL EXCEPTION: main E/AndroidRuntime(16522): java.lang.RuntimeException: Unable to start activityComponentInfo{com.production.MyApp/com.project.MyApp.AddEvent.AddEventMapAc
E/AndroidRuntime(16522): FATAL EXCEPTION: main
E/AndroidRuntime(16522): java.lang.RuntimeException: Unable to start activityComponentInfo{com.production.MyApp/com.project.MyApp.AddEvent.AddEventMapActivity}:
android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime(16522): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime(16522): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
E/AndroidRuntime(16522): at android.app.Activity.setContentView(Activity.java:1892)
E/AndroidRuntime(16522): at com.project.MyApp.AddEvent.AddEventMapActivity.onCreate(AddEventMapActivity.java:20)
E/AndroidRuntime(16522): 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" />
E/AndroidRuntime(16522): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
E/AndroidRuntime(16522): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
E/AndroidRuntime(16522): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
E/AndroidRuntime(16522): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
您需要将以下内容添加到清单文件中
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
将其放在清单的末尾,映射API键元数据标记之后
退房
这是从google play services上一次13版更新中添加的新要求。您需要在清单中添加以下内容
...
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
。。。
此信息可在logcat错误消息中找到
也在网站上
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
...
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>