Fixed
Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 1185eb405a5bba974c3b32e617750473084159a0
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Feb 18 12:58:37 2020
Fix FragmentContainerView errors in layout preview
When using FragmentContainerView in xml and going to the layout preview
an UnsupportedOperationException will be thrown because of the
contructor that the layout preview uses to initialize the view.
This change adds a isInEditMode() check to avoid incorrectly spamming
the editor with errors.
Test: Tested in nav integration app, and test app
Bug: 149707833
RelNote: "`FragmentContainerView` no longer throws an
`UnsupportedOperationException` for using the incorrect constructor in
layout preview."
Change-Id: Ia9850eaeb1ad5dad654c62441b9ba0827e30663e
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentContainerView.java
https://android-review.googlesource.com/1238906
Branch: androidx-master-dev
commit 1185eb405a5bba974c3b32e617750473084159a0
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Feb 18 12:58:37 2020
Fix FragmentContainerView errors in layout preview
When using FragmentContainerView in xml and going to the layout preview
an UnsupportedOperationException will be thrown because of the
contructor that the layout preview uses to initialize the view.
This change adds a isInEditMode() check to avoid incorrectly spamming
the editor with errors.
Test: Tested in nav integration app, and test app
Bug: 149707833
RelNote: "`FragmentContainerView` no longer throws an
`UnsupportedOperationException` for using the incorrect constructor in
layout preview."
Change-Id: Ia9850eaeb1ad5dad654c62441b9ba0827e30663e
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentContainerView.java
jb...@google.com <jb...@google.com> #3
This has been fixed internally and will be available in the Fragment 1.3.0-alpha01 release.
Description
Version used: 1.2.1
If you use a FragmentContainerView in an XML layout and use the layout preview, an error will be printed in the preview's errors view:
```
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 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:404)
(omitted)
```
It might be good to add a check for isInEditMode, or alternatively remove the constructor overloads that throw (since the default Context-only one doesn't throw).