抛出:IllegalArgumentException:没有碎片中找到了ID视图 [英] IllegalArgumentException: No view found for id in fragments
问题描述
我试图寻找一切都是那么的问题,但它似乎由于缺少的setContentView或需要清理的项目,我的问题了,我得到java.lang.IllegalArgumentException异常:没有查看发现ID,但它的随机我想不通为什么有些器件抛出此异常我有
活动 - > FragmentA->嵌套片段
伟大工程,但有时很多,当我尝试打开我的应用程序崩溃此其code在OncreateView时间后
如果(savedInstanceState == NULL)
{
尝试{ FragmentDestination F = FragmentDestination.newInstance(NULL,NULL);
f.setOnDestinationSelectedListener(本);
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.destinationHolder,f).commit();
}赶上(抛出:IllegalArgumentException前){ex.printStackTrace();} }
这似乎运作良好,但一段时间后它的异常升高(destinationHolder它的一个容器的FrameLayout)
有时如果我使用
活动 - > FragmentA->嵌套FragmentA-> replaceFragmentA
使用下一个code有时会抛出异常。
有何建议?谢谢
这可能是因为你的活动或片段没有被正确缓存和再创造崩溃的应用程序。
尝试调用
super.onCreate(NULL);
和看看问题是否会消失。如果是这样,那么你就需要适当地保存实例状态为您的碎片和活动,让他们正确地重新创建。
您可以阅读更多关于这个和<一rel=\"nofollow\"> HREF =http://stackoverflow.com/q/26966623/3249477>这里是它有这个问题类似的问题。
I tried searching all SO questions but seems its because missing setContentView or need clean the project, my issue its i got java.lang.IllegalArgumentException: No view found for id but its "random" i can't figure out why some devices throw this exception i have Activity->FragmentA->Nested fragment and works great but sometimes after a lot of time when i try to open my app crash this its the code in OncreateView
if(savedInstanceState==null)
{
try {
FragmentDestination f = FragmentDestination.newInstance(null,null);
f.setOnDestinationSelectedListener(this);
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.destinationHolder,f).commit();
}catch (IllegalArgumentException ex){ex.printStackTrace();}
}
This seems to work well but some time the exception its raised (destinationHolder its a frameLayout container)
and sometimes if i use Activity->FragmentA->Nested FragmentA-> replaceFragmentA using the next code sometimes raise the exception.
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.nested_fragment_a,f).commit();
Any advice? Thanks
It could be that your activity or fragment isn't being properly cached and a re-creation crashes the app.
Try calling
super.onCreate(null);
and see if the problem goes away. If so then you'll need to properly save the instance states for your fragments and activity, so they're re-created properly.
You can read more about this here and here's a similar question which had this problem.
这篇关于抛出:IllegalArgumentException:没有碎片中找到了ID视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!