I have a (more complex) version of these 4 classes the problem is when I try to initialize Test()
android studio tells me cannot call data.log() on a null object reference
. Why is this? how can i fix it?
abstract class Test() {
protected abstract val data: CustomClass
init {
data.log()
}
}
class myClass(): Test() {
override val data = Hello()
}
abstract class CustomClass() {
function log() {
Log.i("TEST", "HELLO");
}
}
class Hello(): CustomClass() {
}
I have a lot of classes that extend Test()
and Hello()
I do not want to have to call data.log()
in multiple classes to avoid repeating code