The following classes could not be instantiated:
androidx.fragment.app.FragmentContainerView(Open Class, Show Exception, Clear Cache)Tip: Use
View.isInEditMode()in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout.Exception Details:
java.lang.UnsupportedOperationException: FragmentContainerView must be within a FragmentActivity to be instantiated from XML. at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.java:117) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1123) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1097) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084) at android.view.LayoutInflater.inflate(LayoutInflater.java:682) at android.view.LayoutInflater.inflate(LayoutInflater.java:501)
This message was shown and layout preview was not shown in basic activity or other template accept empty activity.
Before this message, one message was shown about replacing fragment tag with fragmentcontainerview. I fixed this and then the above message was shown. I have tried known solutions like rebuild, refresh layout and invalidate caches/restart, etc, but they didn't do the trick.
If you look at the source code for
FragmentContainerView, you'll see this:Unfortunately, this is the constructor that the layout preview invokes. It doesn't seem that there's anything you can do about this error until the Android Studio team fixes this issue.
This is the constructor the system is "supposed" to use:
If you actually run your app, this should be invoked and everything should work just fine.