I've looked at multiple questions, haven't found solution yet.
I've youtube player SDK imported and a webview. One is in Live_fragment and another Article_Fragment.
This is the onBackPressed code that causes the crash:
@Override
override fun onBackPressed() {
if (webViewE.canGoBack() || youTubePlayer.isFullScreen()) {
youTubePlayer.exitFullScreen()
webViewE.goBack()
} else {
super.onBackPressed()
}
}
Now, webViewE.canGoBack
and youTubePlayer.isFullScreen()
alone works fine (if I only put in one of them), but if they're both together in the function, I get:
Attempt to invoke virtual method 'boolean android.webkit.WebView.canGoBack()' on a null object reference" and app crashes