<bdo id='gd6Ba'></bdo><ul id='gd6Ba'></ul>

        <i id='gd6Ba'><tr id='gd6Ba'><dt id='gd6Ba'><q id='gd6Ba'><span id='gd6Ba'><b id='gd6Ba'><form id='gd6Ba'><ins id='gd6Ba'></ins><ul id='gd6Ba'></ul><sub id='gd6Ba'></sub></form><legend id='gd6Ba'></legend><bdo id='gd6Ba'><pre id='gd6Ba'><center id='gd6Ba'></center></pre></bdo></b><th id='gd6Ba'></th></span></q></dt></tr></i><div id='gd6Ba'><tfoot id='gd6Ba'></tfoot><dl id='gd6Ba'><fieldset id='gd6Ba'></fieldset></dl></div>

        <small id='gd6Ba'></small><noframes id='gd6Ba'>

      1. <legend id='gd6Ba'><style id='gd6Ba'><dir id='gd6Ba'><q id='gd6Ba'></q></dir></style></legend>
        <tfoot id='gd6Ba'></tfoot>

        仅在第二次导航到 Fragment 时导致 java.IllegalStateException 错误,No Activ

        时间:2023-10-04
        1. <small id='xBdYo'></small><noframes id='xBdYo'>

            <bdo id='xBdYo'></bdo><ul id='xBdYo'></ul>
            <tfoot id='xBdYo'></tfoot>

              <i id='xBdYo'><tr id='xBdYo'><dt id='xBdYo'><q id='xBdYo'><span id='xBdYo'><b id='xBdYo'><form id='xBdYo'><ins id='xBdYo'></ins><ul id='xBdYo'></ul><sub id='xBdYo'></sub></form><legend id='xBdYo'></legend><bdo id='xBdYo'><pre id='xBdYo'><center id='xBdYo'></center></pre></bdo></b><th id='xBdYo'></th></span></q></dt></tr></i><div id='xBdYo'><tfoot id='xBdYo'></tfoot><dl id='xBdYo'><fieldset id='xBdYo'></fieldset></dl></div>

              • <legend id='xBdYo'><style id='xBdYo'><dir id='xBdYo'><q id='xBdYo'></q></dir></style></legend>
                  <tbody id='xBdYo'></tbody>

                  本文介绍了仅在第二次导航到 Fragment 时导致 java.IllegalStateException 错误,No Activity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我遇到了一个非常令人费解的错误,我什至不知道如何开始解决.

                  I am getting a very puzzling bug that I have no idea how to even begin working through.

                  我有一个带有一个活动的简单应用程序,视图是用片段实现的.其中一个片段内部有一个 ViewPager;所以我决定我想使用 v4 支持库的 getChildFragmentManager 类.我还必须使用 ActionBarSherlock,这会导致问题,因为它没有随 v4 库的 v11 一起提供.

                  I have a simple app with one activity, the views are implemented with Fragments. One of the fragments has a ViewPager inside of it; so I decided I that I wanted to use the getChildFragmentManager class of the v4 support library. I also had to use ActionBarSherlock, which caused a problem, because it does not ship with the v11 of the v4 library.

                  我通过将 ABS 中的 v4 支持库替换为 v11 库来解决此问题,并且所有内容都已编译并似乎可以正常工作,包括 ViewPager.

                  I fixed this by replacing the v4 support library in ABS with the v11 library, and everything compiled and appeared to be working, including the ViewPager.

                  这是奇怪的部分:

                  第一次打开带有 ViewPager 的 Fragment,它可以正常工作;但是第二次导航到,应用程序崩溃,给出一个无用的堆栈跟踪.通过调试,我发现问题出在 getChildFragmentManager 返回的 FragmentManager 上;它抛出无活动错误.

                  The first time the fragment with the ViewPager opens, it works properly; but the SECOND time it is navigated to, the app crashes, giving a useless stack trace. From debugging, I discovered that the problem was with the FragmentManager returned by getChildFragmentManager; it throws the No Activity error.

                  有人知道是什么原因造成的吗?

                  Does anybody have any idea what could be causing this?

                  我将发布您认为相关的代码.

                  I will post code that you think is relevant.

                  谢谢你,大卫

                  推荐答案

                  我点击了 jeremyvillalobos answer 中的链接(其中非常有帮助)这导致我这个解决方法.

                  I followed the link in jeremyvillalobos answer (which was very helpful) that led me to this workaround.

                  public class CustomFragment extends Fragment {
                      private static final Field sChildFragmentManagerField;
                  
                      static {
                          Field f = null;
                          try {
                              f = Fragment.class.getDeclaredField("mChildFragmentManager");
                              f.setAccessible(true);
                          } catch (NoSuchFieldException e) {
                              Log.e(LOGTAG, "Error getting mChildFragmentManager field", e);
                          }
                          sChildFragmentManagerField = f;
                      }
                  
                      @Override
                      public void onDetach() {
                          super.onDetach();
                  
                          if (sChildFragmentManagerField != null) {
                              try {
                                  sChildFragmentManagerField.set(this, null);
                              } catch (Exception e) {
                                  Log.e(LOGTAG, "Error setting mChildFragmentManager field", e);
                              }
                          }
                      }
                  
                      ...
                  }
                  

                  它对我很有效,无需重新实例化片段.

                  It works for me well, without the need to reinstantiate the fragment.

                  这篇关于仅在第二次导航到 Fragment 时导致 java.IllegalStateException 错误,No Activity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:ViewPager Activity 通知特定事件的 Fragment 下一篇:DialogFragment 中的 ViewPager - IllegalStateException:片段没有视图

                  相关文章

                    <bdo id='R3YHM'></bdo><ul id='R3YHM'></ul>

                  <tfoot id='R3YHM'></tfoot>
                    <legend id='R3YHM'><style id='R3YHM'><dir id='R3YHM'><q id='R3YHM'></q></dir></style></legend>

                    <small id='R3YHM'></small><noframes id='R3YHM'>

                      <i id='R3YHM'><tr id='R3YHM'><dt id='R3YHM'><q id='R3YHM'><span id='R3YHM'><b id='R3YHM'><form id='R3YHM'><ins id='R3YHM'></ins><ul id='R3YHM'></ul><sub id='R3YHM'></sub></form><legend id='R3YHM'></legend><bdo id='R3YHM'><pre id='R3YHM'><center id='R3YHM'></center></pre></bdo></b><th id='R3YHM'></th></span></q></dt></tr></i><div id='R3YHM'><tfoot id='R3YHM'></tfoot><dl id='R3YHM'><fieldset id='R3YHM'></fieldset></dl></div>