-
Notifications
You must be signed in to change notification settings - Fork 552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullPointerException initStickyHeadersHolder on orientation change #512
Comments
@skimarxall, yes, thank you. |
@skimarxall, I'm trying to reproduce as you described but I don't get the exception! Then, I looked what is that line: the code is expecting a FrameLayout wrapping the RecyclerView, and the We know, if we are using a Fragment, we have access to the RecyclerView instance after the view is created. it must have that layout also when you rotate. Adapter seems to not be detached from the old RecyclerView. Which Android version are you using? I tried with 8.0. |
Hi, thanks to take a look. it happens in a Samsung with v21 and in the emulator v26. As mentioned is hard to reproduce manually so I add a breakpoint on the onCreate, on that moment I turn the device and continue the debugger. What it might be important to say is that I am initializing the adapter onActivityCreated inside the fragment. override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
userFeedAdapter
.addListener(this)
.setStickyHeaders(true)
.setDisplayHeadersAtStartUp(true)
.setAnimationOnForwardScrolling(true)
userFeedAdapter.stickyHeaderElevation = resources.getDimensionPixelSize(R.dimen.spacing_8)
userFeedList.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
userFeedList.adapter = userFeedAdapter
} So, what I can see with the debugger is: Activity onCreate -> Turn device -> onAcrtivityCreated -> Init adapter -> Activity recreates -> onActivityCreated is called again (new view, new adapter) -> init new adapter -> Post runnable from old adapter is called -> NullPointer because it misses the reference. |
@skimarxall, ah the breakpoint is in |
@skimarxall, I don't get the exception, the parent layout is never null in the 2 calls, can you show me your layout where the RV is present? |
I've put an extra check, even it's so difficult to reproduce it, since the parent layout must always be present if the RecyclerView instance is valid! |
Thanks for fixing it. |
Situation:
The problem is this piece of code
Since you are posting a runnable if the timing is good it will be executed after onDestroyView.
Possible solutions, check if recylcer is still there or remove the runnable.
The text was updated successfully, but these errors were encountered: