Reputation: 9994
I have following ViewModel class :
class PersonViewModel(
context: Application,
private val dataSource: MoviesRemoteDataSource)
: AndroidViewModel(context) {
internal val compositeDisposable = CompositeDisposable()
val person: ObservableField<Person>()
private val isVisible = ObservableBoolean(false)
fun showPerson(personId: String) {
val personSubscription = dataSource.getPerson(personId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ person ->
isVisible.set(true)
this.person.set(person)
}
) { throwable -> Timber.e(throwable) }
compositeDisposable.add(personSubscription)
}
}
And this is Person class :
class Person(
@SerializedName("birthday")
var birthDay: String?,
@SerializedName("deathday")
var deathDay: String?,
var id: Int,
@SerializedName("also_known_as")
var alsoKnowAs: List<String>,
var biography: String,
@SerializedName("place_of_birth")
var placeOfBirth: String?)
It shows an error on this line in ViewModel:
val person: ObservableField<Person>()
It says : property getter or setter expected
I appreciate for your help.
Upvotes: 9
Views: 7562
Reputation: 3987
looking at your code:
val person: ObservableField<Person>()
you have a simple syntax error the parentheses after type! remove them or change colon to assign sign:
val person: ObservableField<Person>
or
val person = ObservableField<Person>()
Upvotes: 4
Reputation: 1007624
Most likely, replace:
val person: ObservableField<Person>()
with:
val person = ObservableField<Person>()
This sets up person
to be initialized with the ObservableField<Person>
that you are creating.
Upvotes: 34