gpt4 book ai didi

android - 无法扩充 android.view.inflateException.Binary xml 文件行 #2

转载 作者:行者123 更新时间:2023-11-29 21:01:27 25 4
gpt4 key购买 nike

friend 们请帮帮我.. 我有一个显示谷歌地图的简单应用程序..当我运行该应用程序时出现错误“不幸的是该应用程序已停止”

log cat 中的错误是:Failed to inflateandroid.view.inflateException.Binary xml 文件第 2 行:在 android view.LayoutInflater.createViewFromTag(LayoutInflater.java.713) 中膨胀类 fragment 时出错

我已经尝试了 stackoverflow 和许多其他网站提供的许多答案。但在所有这些情况下,我都会遇到同样的错误。

我的代码:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />

主 Activity .java

package info.androidhive.googlemapsv2;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

public class MainActivity extends FragmentActivity {

private GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.mapview)).getMap();
}
}

list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.googlemapsv2"
android:versionCode="1"
android:versionName="1.0" >

<permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />

<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />

<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" />

<!-- Requires OpenGL ES version 2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="info.androidhive.googlemapsv2.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBZMlkOv4sj-M5JO9p6wksdax4TEjDVLgo" />
</application>

</manifest>

堆栈跟踪:

09-23 04:46:45.287: D/AndroidRuntime(2653): Shutting down VM
09-23 04:46:45.287: W/dalvikvm(2653): threadid=1: thread exiting with uncaught exception (group=0xb1d8db20)
09-23 04:46:45.287: E/AndroidRuntime(2653): FATAL EXCEPTION: main
09-23 04:46:45.287: E/AndroidRuntime(2653): Process: info.androidhive.googlemapsv2, PID: 2653
09-23 04:46:45.287: E/AndroidRuntime(2653): 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
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.os.Handler.dispatchMessage(Handler.java:102)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.os.Looper.loop(Looper.java:136)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-23 04:46:45.287: E/AndroidRuntime(2653): at java.lang.reflect.Method.invokeNative(Native Method)
09-23 04:46:45.287: E/AndroidRuntime(2653): at java.lang.reflect.Method.invoke(Method.java:515)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-23 04:46:45.287: E/AndroidRuntime(2653): at dalvik.system.NativeStart.main(Native Method)
09-23 04:46:45.287: E/AndroidRuntime(2653): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.app.Activity.setContentView(Activity.java:1929)
09-23 04:46:45.287: E/AndroidRuntime(2653): at info.androidhive.googlemapsv2.MainActivity.onCreate(MainActivity.java:17)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.app.Activity.performCreate(Activity.java:5231)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
09-23 04:46:45.287: E/AndroidRuntime(2653): ... 11 more
09-23 04:46:45.287: E/AndroidRuntime(2653): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 5089000 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" />
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.google.android.gms.maps.internal.u.I(Unknown Source)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.google.android.gms.maps.internal.u.H(Unknown Source)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.google.android.gms.maps.SupportMapFragment$b.jz(Unknown Source)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.google.android.gms.dynamic.a.a(Unknown Source)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
09-23 04:46:45.287: E/AndroidRuntime(2653): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
09-23 04:46:45.287: E/AndroidRuntime(2653): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
09-23 04:46:45.287: E/AndroidRuntime(2653): ... 21 more

最佳答案

像这样将您的 map fragment 放在 RelativeLayout 或 LinearLayout 中;

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment
android:id="@+id/mapview"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

</RelativeLayout>

然后改变

map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.mapview)).getMap();

有了这个;

setUpMap();

setUpMap() 函数定义将是;

private void setUpMap(){
if (map != null) {
return;
}
map=((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapview)).getMap();
if (map == null) {
return;
}
}

编辑

哦,你也很想念

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

在您的 list 文件中。检查this link

关于android - 无法扩充 android.view.inflateException.Binary xml 文件行 #2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25990445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com