Day130 — Kotlin synthetic binding view is null

Jacky Tsang
1 min readDec 10, 2019

--

By default, Android Extensions adds a hidden cache function and a storage field to each container (Activity, Fragment, View or a LayoutContainer implementation) written in Kotlin

Well, it’s nothing magical, if you decompile the bytecode (By going toTools -> Kotlin -> Show Kotlin Bytecode and then selecting Decompile in the pane) and take a look at the generated java class, you’ll see that all it does is call findViewById() for us.

It is best to add ? after a view generated from kotlin android extension in case the view is null. (Kotlin will return View!)

abc?.visibility = View.GONE

--

--

No responses yet