androidbroadcast / ViewBindingPropertyDelegate

Make work with Android View Binding simpler
https://proandroiddev.com/make-android-view-binding-great-with-kotlin-b71dd9c87719
Apache License 2.0
1.42k stars 102 forks source link

How to use with BaseActivity? #42

Closed goodibunakov closed 3 years ago

goodibunakov commented 3 years ago

Or with BaseFragment

kirich1409 commented 3 years ago

Please describe the issue

goodibunakov commented 3 years ago

I have to use BaseActivity in my project. I did:

class SplashActivity : BaseActivity<SplashViewModel>() {
    private val binding by viewBinding(ActivitySplashBinding::bind, R.id.container) 
}

abstract class BaseActivity<T : BaseActivityViewModel> : AppCompatActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
           super.onCreate(savedInstanceState)
     }
}

And received: Unable to start activity ComponentInfo{....SplashActivity}: java.lang.NullPointerException: activity.findViewById(viewBindingRootId) must not be null

kirich1409 commented 3 years ago

You need to set content view before access to the viewbinding delegate