In my case it comes when i want to add view by parent to other view
View root = inflater.inflate(R.layout.single, null); LinearLayout lyt = root.findViewById(R.id.lytRoot); lytAll.addView(lyt); //it crashes
So to avoid the crash one must add parent view like this
View root = inflater.inflate(R.layout.single, null); LinearLayout lyt = root.findViewById(R.id.lytRoot); lytAll.addView(root); //it works fine
I followed above steps and my issue got resolved.