Ciaran Sloan
09/04/2025, 2:08 PMprivate lateinit var scrollView: ScrollView
fun onCreateView(): View? {
val view = super.onCreateView()
if (view != null) {
scrollView = view.findViewById(R.id.scoll_view)
}
}
The crash happens at the assignment of findViewById, as the layout doesn't actually exist. We didn't notice this crash as it's in an abstraction and this property isn't actually accessed or read.
However since bumping to Kotlin 2.2 this crashes with an NPE - which is actually expected.
Does anyone know what might have changed in 2.2 that might have caused this? Or why we wouldn't have seen this prior to 2.2?Pavel Habžanský
09/04/2025, 3:55 PMCiaran Sloan
09/04/2025, 3:58 PMGurpreetSK
09/04/2025, 6:03 PMCiaran Sloan
09/04/2025, 6:58 PMGurpreetSK
09/05/2025, 1:05 AMtextView
is still a platform type, the nullability is unknown and is on the developer to decide whether to handle it as a null or non-nullable type. So if the value is null, the app should have still crashed. I verified this by setting a click listener on text to when it crashed every time doing activity creation, unless I handled it as a null type.
2. The lint warning - did this not show for you? This doesn’t answer the question but would’ve completely avoided the crash.Ciaran Sloan
09/05/2025, 9:45 AMGurpreetSK
09/05/2025, 3:26 PM