Я пытаюсь создать экземпляр ViewModel, используя компоненты архитектуры Android в моем фрагменте с Kotlin, и получаю следующую ошибку:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: campanoon.cronometrohiit, PID: 3871
java.lang.RuntimeException: Cannot create an instance of class campanoon.cronometrohiit.RoutinesViewModel
at android.arch.lifecycle.ViewModelProvider$NewInstanceFactory.create(ViewModelProvider.java:153)
Моя ViewModel:
class RoutinesViewModel(application: Application) : ViewModel() {
private val routineDao = AppDatabase.getDatabase(application).routineDao()
fun generateSimpleList() : List<Routine> {
routineDao.insertRoutine(Routine(null,"Prueba 1", "00:10","00:30","30:00",3))
routineDao.insertRoutine(Routine(null,"Prueba 2", "00:15","00:30","15:00",2))
routineDao.insertRoutine(Routine(null,"Prueba 3", "00:20","00:30","20:00",5))
return routineDao.getRoutines()
}
}
Мой фрагмент:
class RoutinesFragment : Fragment() {
private lateinit var routinesViewModel : RoutinesViewModel
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val v : View = inflater.inflate(R.layout.fragment_routines, container, false)
routinesViewModel= ViewModelProviders.of(this).get(RoutinesViewModel::class.java)
return v
}
Я не знаю, что я делаю не так: (