Closed Saloni123456 closed 6 years ago
If a ViewModel is being initialised by ViewModelProviders.of(this).get(UserViewModel.class);
, then we need a pass zero constructors. But in this example, we are passing the Application class to the constructor so this was not working. Fixed it. Please pull the changes
Hi, i am not able to launch app. Receiving below issue in logcat. I looked for solutions and tried them but still got the same error.
07-07 11:28:03.513 18254-18254/com.an.paginglibrary.sample E/AndroidRuntime: FATAL EXCEPTION: main Process: com.an.paginglibrary.sample, PID: 18254 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.an.paginglibrary.sample/com.an.paginglibrary.sample.activity.FeedActivity}: java.lang.RuntimeException: Cannot create an instance of class com.an.paginglibrary.sample.viewmodel.FeedViewModel at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2678) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6165) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778) Caused by: java.lang.RuntimeException: Cannot create an instance of class com.an.paginglibrary.sample.viewmodel.FeedViewModel at android.arch.lifecycle.ViewModelProvider$NewInstanceFactory.create(ViewModelProvider.java:153) at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:210) at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134) at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102) at com.an.paginglibrary.sample.activity.FeedActivity.onCreate(FeedActivity.java:36) at android.app.Activity.performCreate(Activity.java:6687) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6165) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778) Caused by: java.lang.InstantiationException: java.lang.Class has no zero argument constructor
at java.lang.Class.newInstance(Native Method)
at android.arch.lifecycle.ViewModelProvider$NewInstanceFactory.create(ViewModelProvider.java:151)
at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:210)
at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134)
at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102)
at com.an.paginglibrary.sample.activity.FeedActivity.onCreate(FeedActivity.java:36)
at android.app.Activity.performCreate(Activity.java:6687)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)