Android Architecture Components — Room, LiveData and ViewModel
subhrajyoti sen
1.3K14

Your article is awesome but i faced an error while creating my BorrowdViewModel object because it extends AndroidViewModel and it have only one constructor.

public BorrowedViewModel(Application application) {
super(application);

appDatabase = AppDatabase.getDatabase(this.getApplication());

itemAndPersonList = appDatabase.itemAndPersonModel().getAllBorrowedItems();
}

So Whenever in my activity it want to create instance my app crashes and through the exception

Could not create instance of BrrrowedViewModel..

I am also little surprise how it will create BorrowedViewModel have one Application’s Constructor ??

viewModel = ViewModelProviders.of(this).get(BorrowedViewModel.class);
Like what you read? Give waqas akram a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.