https://kotlinlang.org logo
p

Piotr Prus

03/07/2021, 7:58 PM
I have this strange error that do not point to anything in my code and it crashes the app. I have Bottom Navigation, where one fragment (start destination) is 100% done in compose. When I start the app everything works fine, but when I go to other fragment and go back to my main (compose), I got this crash. Anyone saw something like this before?
Copy code
java.lang.NullPointerException: Attempt to invoke interface method 'void androidx.compose.runtime.MutableState.setValue(java.lang.Object)' on a null object reference
        at androidx.compose.ui.platform.AndroidComposeView.setLayoutDirection(AndroidComposeView.android.kt:930)
        at androidx.compose.ui.platform.AndroidComposeView.onRtlPropertiesChanged(AndroidComposeView.android.kt:768)
        at android.view.View.resolvePadding(View.java:20272)
        at android.view.ViewGroup.resolvePadding(ViewGroup.java:7765)
        at android.view.View.initializeScrollbarsInternal(View.java:6781)
        at android.view.View.<init>(View.java:6112)
        at android.view.ViewGroup.<init>(ViewGroup.java:697)
        at android.view.ViewGroup.<init>(ViewGroup.java:693)
        at android.view.ViewGroup.<init>(ViewGroup.java:689)
        at android.view.ViewGroup.<init>(ViewGroup.java:685)
        at androidx.compose.ui.platform.AndroidComposeView.<init>(AndroidComposeView.android.kt:115)
        at androidx.compose.ui.platform.Wrapper_androidKt.setContent(Wrapper.android.kt:79)
        at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:175)
        at androidx.compose.ui.platform.AbstractComposeView.onAttachedToWindow(ComposeView.android.kt:207)
        at android.view.View.dispatchAttachedToWindow(View.java:20479)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3489)
        at android.view.ViewGroup.addViewInner(ViewGroup.java:5278)
        at android.view.ViewGroup.addView(ViewGroup.java:5064)
        at androidx.fragment.app.FragmentContainerView.addView(FragmentContainerView.java:290)
        at android.view.ViewGroup.addView(ViewGroup.java:5004)
        at androidx.fragment.app.FragmentStateManager.addViewToContainer(FragmentStateManager.java:830)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:520)
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2177)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2094)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1990)
        at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7660)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
tl;dr: should be fixed in beta02. In the meantime, look for any places in your app theme xml files that set scrollbar attributes globally to the theme and remove them
those being present during inflation causes View to invoke non-final methods to update rtl properties in its constructor
p

Piotr Prus

03/07/2021, 8:17 PM
Thanks. I thought it might be at the issuetracker. I was looking for “NPE”, etc. Great that it will be fixed soon. 🙂
setting
Copy code
<item name="android:scrollbars">none</item>
globally, solved the issue 👌
a

Adam Powell

03/07/2021, 8:23 PM
nice; considering that's the default though, I might also look to see what's turning it on the in first place 🙂
that was never meant to be an attribute that appears at the theme level since it makes no sense; what does it mean to specify that toggle switches should have vertical scrollbars anyway? 🙃 whatever is setting that globally is a bug too since it's kind of nonsense
p

Piotr Prus

03/07/2021, 8:42 PM
I have checked the codebase and there are 2 places with
android:scrollbars
and these are RVs. Nothing suspicious here. Maybe some library is setting it or another android view?
👍 1
c

Colton Idle

03/07/2021, 9:43 PM
@Piotr Prus do you by any chance use a library for a debug drawer? I'm having the same issue and the debug drawer is the only thing I could think of.
s

Shivam Sethi

03/07/2021, 11:06 PM
Same issue, hope this will get fixed.
a

Adam Powell

03/07/2021, 11:12 PM
beta02 releases this Wednesday if all goes as planned, or you can try the snapshot builds from androidx.dev to confirm the fix
🙌 1
s

Shivam Sethi

03/08/2021, 12:26 AM
I will wait for the next build on Wednesday or when it comes, to get around with this I hosted another activity in the single activity app which I will translate back to fragment using fixed compose view
p

Piotr Prus

03/08/2021, 6:17 AM
@Colton Idle I have this issue on quite big project, where many engineers used a lot libraries before i join. We are now trying to clean it, go 100% compose. I have no idea which library, out of million, can cause it 🙃