Kotlin ViewHolder类提供了房间数据库错误
我正在尝试将房间数据库添加到我之前制作的测验应用程序中。 我得到这个错误:Kotlin ViewHolder类提供了房间数据库错误,kotlin,android-room,Kotlin,Android Room,我正在尝试将房间数据库添加到我之前制作的测验应用程序中。 我得到这个错误: /Users/olofhammar/AndroidStudioProjects/QuizApp1/app/build/tmp/kapt3/stubs/debug/com/example/quizapp1/SetNrOfQuestionsFragment.java:7: error: cannot find symbol private FragmentCommunicator fragmentCommunicat
/Users/olofhammar/AndroidStudioProjects/QuizApp1/app/build/tmp/kapt3/stubs/debug/com/example/quizapp1/SetNrOfQuestionsFragment.java:7: error: cannot find symbol
private FragmentCommunicator fragmentCommunicator;
^
symbol: class FragmentCommunicator
location: class SetNrOfQuestionsFragment[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC)
它还说“生成”文件夹下的文件已生成,不应编辑”
导致崩溃的实现是:
kapt "androidx.room:room-compiler:$room_version"
我使用viewmodel类在片段之间进行通信。那个班看起来像这样
class FragmentCommunicator : ViewModel(){
val nrOfQuestions = MutableLiveData<Any>()
fun sendNrOfQuestions(nr:Int){
nrOfQuestions.setValue(nr)
}
}
private var fragmentCommunicator: FragmentCommunicator? = null
private var totalNrOfQuestions = 0
private var soundPool = SoundPool()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_set_nr_of_questions, container, false)
fragmentCommunicator= ViewModelProviders.of(activity!!).get(FragmentCommunicator::class.java)
感谢您的建议。您是指ViewModel而不是ViewHolder吗?另外,请提供部分实际房间代码。