Reputation: 254
I'm working on an Android project and I'm using Firebase as my backend. I've created a module that will handle all Firestore related work. In this module, I created this class:
import com.google.firebase.firestore.DocumentReference
import java.util.*
data class SurveyDto(
var id: String = "",
var name: String = "",
var type: String = "",
var creationDate: Date = Date(),
var createdBy: DocumentReference? = null,
var current: Boolean = true,
var sections: List<SectionDto> = listOf()
)
In my main Module I created a Mapper class that will be in charge of converting my SurveyDto
object into a Survey
object (mapping logic was omitted for simplicity):
class SectionDtoMapper: DomainMapper<SectionDto, Section> {
private val questionDtoMapper = QuestionDtoMapper()
override fun mapToDomainModel(model: SectionDto): Section {
return Section()
}
override fun mapFromDomainModel(domainModel: Section): SectionDto {
return SectionDto()
}
}
The problem is that, if I try running the app, it shows this runtime exception at return SectionDto()
:
Cannot access class 'com.google.firebase.firestore.DocumentReference'. Check your module classpath for missing or conflicting dependencies
If I remove the var createdBy: DocumentReference? = null
attribute from my SurveyDto
class, or if I remove the return SectionDto()
code, the app runs just fine.
I'm importing this to my firebase module:
implementation platform("com.google.firebase:firebase-bom:26.8.0")
implementation "com.google.firebase:firebase-firestore-ktx"
// Some other firebase and non firebase imports
On my main module, i'm importing:
implementation platform(rootProject.ext.firebase.bom)
implementation project(':libraries:firebase_api')
// Some other firebase and non firebase imports
Please keep in mind that I have a lot of objects that import DocumentReference
, but they're all written in Java... Don't know if this could be related!
Do you have any idea what could be wrong?
Upvotes: 0
Views: 613
Reputation: 254
So, I solved my problem adding manually an empty constructor for my data class:
import com.google.firebase.firestore.DocumentReference
import java.util.*
data class SurveyDto(
var id: String,
var name: String,
var type: String,
var creationDate: Date,
var createdBy: DocumentReference?,
var current: Boolean,
var sections: List<SectionDto>
) {
constructor() : this(
id = "",
name = "",
type = "",
creationDate = Date(),
createdBy = null,
current = true,
sections = listOf()
)
}
I have no idea why this fixed my problem... I always thought that assigning a default value for each field would be the same as creating a secondary constructor
Upvotes: 1