[Leanback] Header State initialized with `HEADERS_HIDDEN` cause Fragment.getView() to not be null
See original GitHub issueExpected Behavior
Reference:
App launched with setHeaderState(HEADERS_HIDDEN)
should hide the header and still display the rows.
Current Behavior
On app launched, it is not displaying any items in the MainFragment.java
.
Pressing anything else on the D-pad (e.g. Press down), it will crash the app with the logs below:
2020-01-10 18:23:40.662 32294-32294/com.example.android.tvleanback E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.tvleanback, PID: 32294
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View androidx.fragment.app.Fragment.getView()' on a null object reference
at androidx.leanback.app.BrowseSupportFragment$4.onFocusSearch(BrowseSupportFragment.java:1096)
at androidx.leanback.widget.BrowseFrameLayout.focusSearch(BrowseFrameLayout.java:118)
at android.view.ViewGroup.focusSearch(ViewGroup.java:967)
at android.view.View.focusSearch(View.java:10171)
at android.view.ViewRootImpl$ViewPostImeInputStage.performFocusNavigation(ViewRootImpl.java:4664)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4782)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4605)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4326)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4487)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2435)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1998)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1989)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2412)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Note
Pressing left D-pad will open the Header and start to display the items.
Possible Solution
Steps to Reproduce (for bugs)
Change setHeadersState(HEADERS_ENABLED);
to setHeadersState(HEADERS_HIDDEN);
private void setupUIElements() {
setBadgeDrawable(
getActivity().getResources().getDrawable(R.drawable.videos_by_google_banner, null));
setTitle(getString(R.string.browse_title)); // Badge, when set, takes precedent over title
- setHeadersState(HEADERS_ENABLED);
+ setHeadersState(HEADERS_HIDDEN);
setHeadersTransitionOnBackEnabled(true);
Context
We would like to launch the App without the header.
Your Environment
Build
- Compiled Android SDK version 28
androidx.leanback:leanback:1.0.0
Running on
- Android version 8.1.0
- Xiaomi TV-box (Android TV)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
getView returning null when fragment has been created from ...
Move your method call to be executed during onCreateView , and use the view you are inflating for reference instead of getView() ....
Read more >BrowseFragment - Android Developers
Returns the state of the headers column in the browse fragment. Fragment ... When the task is not null, headers fragment will be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Note, I’ve also filed this at https://issuetracker.google.com/issues/147614095
Thank you for the detailed report! I’ve confirmed this issue and also verified it happens on other devices, with leanback 1.0.0 and 1.1.0-alpha03, whether setHeadersState(HEADERS_HIDDEN) is called in onActivityCreated or onViewCreated.