So, im trying to develop an Android app with Kotlin as an Pen and Paper RPG companion. Right now I want to make a mob class like
class Mob(name: String, health: Int, armor: Int) {
private val name: String
get() = field
private var health: Int = 0
get() = field
set(value) {
field = value
}
private val armor: Int
get() = field
}
In another activity I want to display this information like
class MeinMonster : AppCompatActivity() {
private lateinit var monster: Mob
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_mein_monster)
monster = Mob(
intent.getStringExtra("Name"),
intent.getIntExtra("Health", 20),
intent.getIntExtra("Armor", 0)
)
print()
}
private fun print() {
try {
tvName.text = monster.name
tvHealth.text = "LeP: ${monster.health}"
tvArmor.text = "RS: ${monster.armor}"
} catch (ex:Exception) {
val goBack = Intent(this, MainActivity::class.java)
startActivity(goBack)
}
}
}
Android studio is constantly telling me Cannot access 'name': It is private in 'Mob', though. I thought that's what I got the get()
for?
Maybe someone with more Kotlin experience can help. Thank you in advance.