You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
but I'm getting a compile error on the by getViewModel() line:
Type inference failed: Not enough information to infer parameter T in intline fun <reified T : ViewModel> FragmentActivity.getViewModel(): T
Please specify it explicitly
If I attempt to specify it via getViewModel<MyViewModel>(), I get this compile error:
Missing 'getValue(MyActivity, KPropery<*>)' method on delegate of type 'MyViewModel'
Or if I try:
val viewModel = getViewModel<LoginViewModel>()
I get a runtime NPE when the ViewModel can't get any instance correctly:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Application.registerActivityLifecycleCallbacks(android.app.Application$ActivityLifecycleCallbacks)' on a null object reference
at android.arch.lifecycle.HolderFragment$HolderFragmentManager.holderFragmentFor(HolderFragment.java:169)
at android.arch.lifecycle.HolderFragment.holderFragmentFor(HolderFragment.java:84)
at android.arch.lifecycle.ViewModelStores.of(ViewModelStores.java:47)
at example.MyActivity.<init>(LoginActivity.kt:45)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
Any insights would be greatly appreciated!
The text was updated successfully, but these errors were encountered:
// Bind it to your ActivityclassMyActivity() : AppCompatActivity() {
val viewModel :MyViewModel by getViewModel()
overridefunonCreate(){
super.onCreate()
}
}
I believe I have followed the docs correctly, but I can't seem to get this working.
I have an activity:
And I am instantiating my module in my Application class:
but I'm getting a compile error on the
by getViewModel()
line:If I attempt to specify it via
getViewModel<MyViewModel>()
, I get this compile error:Or if I try:
I get a runtime NPE when the ViewModel can't get any instance correctly:
Any insights would be greatly appreciated!
The text was updated successfully, but these errors were encountered: