Type mismatch. Required: DataStore<UserPreferencesRepository.UserPreferences> Found: DataStore<Preferences>

Open
#75 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
android, kotlin
Domain
mobile

Research direction

Start with TasksActivity and UserPreferencesRepository, then compare their DataStore generic types with step 5 of the linked Android Preferences DataStore codelab. Reproduce the compiler error and confirm the repository constructor and call site use the same preference type so the project builds.

Written by the indexing model from the issue text.

Description

Problem:
I followed every step mentined in the Codelab tutorial https://developer.android.com/codelabs/android-preferences-datastore?hl=zh-cn#5, but I encountered this problem"Type mismatch. Required: DataStore<UserPreferencesRepository.UserPreferences> Found: DataStore".

TasksActivity
viewModel = ViewModelProvider( this, TasksViewModelFactory( TasksRepository, UserPreferencesRepository(dataStore, this) ) ).get(TasksViewModel::class.java)

UserPreferencesRepository
class UserPreferencesRepository constructor( private val userPreferencesStore: DataStore<UserPreferences>, context: Context )... data class UserPreferences(val showCompleted: Boolean)

Dominant language
Kotlin
Stars
240
Forks
113
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from android/codelab-android-datastore

All issues in android/codelab-android-datastore

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.