Я пытаюсь установить свойство объекта, который я создал в Android Studio, используя Kotlin. Я использую для l oop, чтобы каждый раз создавать новый объект и добавлять его в массив. Когда я инициализирую свой объект и пытаюсь установить topId, он говорит: «Val не может быть переназначен», хотя я объявляю его var.
for (i in 1..5) {
var topRanNum = generateRandomNum(topSize)
var top = currentSeasonTops[topRanNum]
var topLoopCounter = 0
var topId = top.id
var newOutfit: Outfit = Outfit()
if(top.wornCount < 5 ) {
newOutfit.topId = top.id
}
}
Класс экипировки
public Outfit() {}
public Outfit(Long topId, Long bottomId, String topPhotoPath, String bottomPhotoPath) {
this.topId = topId;
this.bottomId = bottomId;
this.topPhotoPath = topPhotoPath;
this.bottomPhotoPath = bottomPhotoPath;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTopPhotoPath() {
return topPhotoPath;
}
public String getBottomPhotoPath() {
return bottomPhotoPath;
}
public Long getTopId() {
return topId;
}
public Long getBottomId() {
return bottomId;
}