问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/28637046/illegalargumentexception-no-view-found-for-id-in-fragments