Open prdp89 opened 6 years ago
@Provides @Singleton AppDatabase provideAppDatabase(@DatabaseInfo String dbName, Context context) { return Room.databaseBuilder(context, AppDatabase.class, dbName).fallbackToDestructiveMigration() .build(); }
Appdatabase class wrong argument exception @amitshekhariitbhu
Hi,
I am following same app structure for my app as:
ActivityBuilder.java: `@Module public abstract class ActivityBuilder {
}`
NavigationActivityModule.Java (NavigationActivity which draws Navigation View with NavigationViewModel): `@Module public class NavigationActivityModule {
@Provides ViewModelProvider.Factory mainViewModelProvider(NavigationViewModel navigationViewModel) { return new TraderViewModelFactory<>(navigationViewModel); } }`
CatalogueFragmentProvider.Java (CatalogueFragment which shows as the first fragment inside NavigationView container): @Module public abstract class CatalogueFragmentProvider { @ContributesAndroidInjector(modules = CataloguesFragmentModule.class) abstract CataloguesFragment provideCataloguesFragment(); }
Lastly, CataloguesFragmentModule.Java (contain catalogue view such as RecyclerView inside CatalogueFragment): @Module public class CataloguesFragmentModule {
}
The problem is I am getting the same instance of NavigationViewModel inside the CatalogueViewModel. This throws error by ViewModelFactory since modelClass.isAssignableFrom returns false.
Please help. I stuck into this from last three days and couldn't find any solution by googling too.
Thanks.