Java 在Firestore中转换为对象后返回Null
我有下面这样的数据类Java 在Firestore中转换为对象后返回Null,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,我有下面这样的数据类 data class Course ( val title: String?=null, val image: String?=null, val guid: String?=null, val price: String?=null, val category: String?=null, val instructorName: String?=null, val instructorCode: String?=nu
data class Course (
val title: String?=null,
val image: String?=null,
val guid: String?=null,
val price: String?=null,
val category: String?=null,
val instructorName: String?=null,
val instructorCode: String?=null,
val rating: String?=null
)
当我推送数据时,一切正常,我在firestore中的数据如下(抱歉,我有两种数据,因为尝试和错误)
但我的问题是,当我在viewmodel中使用此执行时
val progressOne = async {
firestore.collection("courses_popular")
.get()
.addOnCompleteListener {task ->
if(task.isSuccessful){
val doc = task.result
if(doc != null){
val res = doc.toObjects(Course::class.java)
popularData.postValue(Response(res, ResponseStatus.SUCCESS))
}else{
popularData.postValue(Response(responseStatus = ResponseStatus.ERROR, msg = "Document null"))
}
}
else{
popularData.postValue(Response(responseStatus = ResponseStatus.ERROR, msg = "${task.exception?.message}"))
}
}
}
为什么我总是得到instructorName和instructorCode空值,但值是存在的?
(这是我在打印控制台时得到的)
材料适应:课程(标题=Belajar Matematika tingkat SMP,
形象=https://storage.googleapis.com/skill-baru.appspot.com/courses_popular/-MI7nXMm1EsCqQX2Shfr/ilustrasi-matematika.jpg,
guid=1,价格=500000,类别=MTK,指令名=null,
instructorCode=null,额定值=4)
D/MateriPopulerAdapter: Course(title=Belajar Matematika tingkat SMP, image=https://storage.googleapis.com/skill-baru.appspot.com/courses_popular/-MI7nXMm1EsCqQX2Shfr/ilustrasi-matematika.jpg, guid=1, price=500000, category=MTK, instructorname=null, instructorcode=null, rating=4)
10-15 15:20:58.984 13736-13736/com.skillbaru.apps W/TabLayout: MODE_SCROLLABLE + GRAVITY_FILL is not supported, GRAVITY_START will be used instead
10-15 15:20:59.005 13736-13736/com.skillbaru.apps D/AndroidRuntime: Shutting down VM
我解决了这个问题,我所做的是将所有参数(在firestore和POJO中)更改为小写(没有驼峰大小写)。同时删除所有camelcase并尝试卸载应用程序,以确保本地设备中没有缓存参数。所以现在一切都正常了。我发现了一个旧版本,其中camelCase的使用影响了字段的检索,是否可以尝试删除整个文档,只使用小写字母,看看它是如何工作的?@Emmanuel你的意思是,我必须将var更改为
instructorname
和instructorcode
?是的,但也尝试删除包含名称为camel case的字段的文档仍然不起作用,我已全部更改并删除camel case,仍然返回null@EmmanuelWait,在我清理应用程序并从零开始后,现在它已存在。真奇怪