繁体   English   中英

找不到片段ID的视图

[英]No view found for id for fragment

我需要帮助。 我在Crashlytics上崩溃了:

Fatal Exception: java.lang.IllegalArgumentException: No view found for id 0x7f0f016c (com.my.my:id/fragment_root_layout) for fragment a{2e8d61e1 #4 id=0x7f0f016c fragment_tag}

我用片段变成片段。 在父片段的OnCreate方法中,我使用帮助FragmentManager添加子片段。 我有个问题,问题是在OnCreate方法中添加了子片段,需要在OnCreateView中执行此操作。 但是我不确定。 问题是我无法重现此崩溃,但我在Crashlytic上遇到了崩溃。 父片段layount上的所有视图都有一个id。 仅当我在OnCreateView方法中膨胀不正确的布局时,我才能重现此崩溃,但是在实时构建中不会发生这种情况。 请给我一个建议。

编辑:添加子片段的代码

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LogUtils.verbose(TAG, "displayOverlayFragment: attempt to add a fragment using FragmentTransaction");
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        OverlayFragment overlayFragment = new OverlayFragment();
        fragmentTransaction.add(R.id.fragment_root_layout, overlayFragment, FRAGMENT_TAG);
        fragmentTransaction.commit();
    }

onCreateView的代码:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutResId(), container, false);
        mRecyclerView = initRecyclerView(view);

        mProgressBar = view.findViewById(R.id.progressBar);
        mProgressBarLabel = (TextView) view.findViewById(R.id.progressBarLabel);
        }

        return view;
}
@Override
    protected int getLayoutResId() {
        return R.layout.fragment_favorites;
    }

也许您必须在发布版本中的proguard-rules.pro中声明一些内容? 您是否仅在发布版本中检查过它? 我认为您的调试版本会忽略proguard,并且工作正常,但是如果您检查发布版本,则将有机会重现崩溃。 也许应该在proguard中声明一些Fragment子组件。

对于android中的片段,您需要在onStart()方法中对其进行编码。 并使用onCreateView()返回要针对该特定片段使用的布局

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM