gpt4 book ai didi

android - 使用保留的 fragment 会导致错误膨胀 SupportMapFragment?

转载 作者:行者123 更新时间:2023-11-30 03:00:18 26 4
gpt4 key购买 nike

在我添加本教程中的 RetainedFragment 之前,我的 map 一直有效 "Handling The Change" .

扩充包含类 com.google.android.gms.maps.SupportMapFragment 的 fragment 的布局时发生错误:

SplashScreenActivity.java 中的 PlaceholderFragment

View rootView = inflater.inflate(R.layout.fragment_splash_screen, container, false);

res/layout/fragment_splash_screen.xml

<fragment
android:id="@+id/app_search_map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />

错误:

android.view.InflateException: Binary XML file line #18: Error inflating class fragment

完整堆栈:

03-25 10:16:51.681: I/Process(31941): Sending signal. PID: 31941 SIG: 9
03-25 10:17:00.141: E/Trace(32468): error opening trace file: No such file or directory (2)
03-25 10:17:00.381: D/AndroidRuntime(32468): Shutting down VM
03-25 10:17:00.381: W/dalvikvm(32468): threadid=1: thread exiting with uncaught exception (group=0x4184c7d0)
03-25 10:17:00.401: E/AndroidRuntime(32468): FATAL EXCEPTION: main
03-25 10:17:00.401: E/AndroidRuntime(32468): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.ericksprengel.piz/br.com.ericksprengel.supportmapfragmentvsretainedfragment.SplashScreenActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2153)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.app.ActivityThread.access$700(ActivityThread.java:137)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.os.Looper.loop(Looper.java:137)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.app.ActivityThread.main(ActivityThread.java:5031)
03-25 10:17:00.401: E/AndroidRuntime(32468): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 10:17:00.401: E/AndroidRuntime(32468): at java.lang.reflect.Method.invoke(Method.java:511)
03-25 10:17:00.401: E/AndroidRuntime(32468): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
03-25 10:17:00.401: E/AndroidRuntime(32468): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
03-25 10:17:00.401: E/AndroidRuntime(32468): at dalvik.system.NativeStart.main(Native Method)
03-25 10:17:00.401: E/AndroidRuntime(32468): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-25 10:17:00.401: E/AndroidRuntime(32468): at br.com.ericksprengel.supportmapfragmentvsretainedfragment.SplashScreenActivity$PlaceholderFragment.onCreateView(SplashScreenActivity.java:72)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.app.Activity.performStart(Activity.java:5068)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2088)
03-25 10:17:00.401: E/AndroidRuntime(32468): ... 11 more
03-25 10:17:00.401: E/AndroidRuntime(32468): Caused by: java.lang.IllegalStateException: Fragment com.google.android.gms.maps.SupportMapFragment did not create a view.
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:314)
03-25 10:17:00.401: E/AndroidRuntime(32468): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-25 10:17:00.401: E/AndroidRuntime(32468): ... 24 more

我不知道 RetainedFragment 和 SupportMapFragment 之间的关系是什么,但只有当我使用 RetainedFragment 时才会出现此错误。

// find the retained fragment on activity restarts
FragmentManager fm = getSupportFragmentManager();
dataFragment = (RetainedFragment) fm.findFragmentByTag("data");

// create the fragment and data the first time
if (dataFragment == null) {
// add the fragment
dataFragment = new RetainedFragment();
fm.beginTransaction().add(dataFragment, "data").commit();
}

如果我删除这一行应用程序不会崩溃

fm.beginTransaction().add(dataFragment, "data").commit();

我创建了一个简单的项目,其中包含一个简单的 Activity,其布局简单,带有 SupportMapFragment 和 RetainedFragment。

简单项目: https://github.com/ericksprengel/support-map-fragment-vs-retained-fragment

最佳答案

我不确定这与您的 RetainedFragment 有什么关系,这很奇怪。

但看起来您的问题与 Having an issue with GoogleMap v2 crashing app on orientation change 有关.

您正在创建一个占位符 fragment ,然后从 xml 加载一个子 fragment 。貌似这样不行,只能动态添加子 fragment 。试试看它是否能解决您的问题。

关于android - 使用保留的 fragment 会导致错误膨胀 SupportMapFragment?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22637210/

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