我尝试制作用户可以将图片和描述添加到我的 firebase 数据库的活动。我按照youtube上的教程来做到这一点。尝试后,我的应用程序中的所有功能看起来都正常,但无法将输入结果输入到firebase中。我的 Firebase 代码:
val filePathAndName="product_images/"+""+timeStamp
val storageReference=FirebaseStorage.getInstance().getReference(filePathAndName)
storageReference.putFile(image_Uri)
.addOnSuccessListener { taskSnapShot->
val uriTask=taskSnapShot.storage.downloadUrl
while(!uriTask.isSuccessful);
val downloadImageUri=uriTask.getResult()
if(uriTask.isSuccessful){
//url diterima
val hashMap:HashMap<String,String> = HashMap<String,String>()
hashMap.put("productId",timeStamp)
hashMap.put("productCategory",kategori)
hashMap.put("productWeight",berat_sampah)
hashMap.put("productDescription",deskripsi)
hashMap.put("productIcon",""+downloadImageUri)
hashMap.put("uid",""+firebaseAuth.uid)
val reference=FirebaseDatabase.getInstance().reference
reference.child(firebaseAuth.uid.toString()).child(Constants.PRODUCT).child(timeStamp).setValue(hashMap)
.addOnSuccessListener {
Toast.makeText(
this@AddProductActivity,
"Berhasil Menambahkan",
Toast.LENGTH_SHORT)
.show()
ClearData()
}
.addOnFailureListener{e->
Toast.makeText(
this@AddProductActivity,
e.message,
Toast.LENGTH_SHORT)
.show()
}
}
}
.addOnFailureListener { e->
Toast.makeText(
this@AddProductActivity,
e.message,
Toast.LENGTH_SHORT)
.show()
}
有人知道我做错了什么吗?
编辑: 所以在我阅读所有日志后,我发现了这个错误:
W/PersistentConnection: pc_0 - Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Database lives in a different region. Please change your database URL to https://rongsokin-97e5c-default-rtdb.asia-southeast1.firebasedatabase.app
它说数据库位于另一个地区,但我将我的数据库设置在东南亚与我的位置相同,为什么会发生这种情况?
答案 0 :(得分:0)
我认为问题是由 dat <- data.frame(id = c("100", "100", "101", "101", "101", "103", "105", "105"),
V1 = c("A", "B", "A", "B", "C", "B", "A", "B"),
V2 = c(NA, NA, 20, NA, 30, NA, 30, 30))
dat <- dat[(dat$V1 == "A" & is.na(dat$V2)) | (dat$V1 == "B" & is.na(dat$V2)), ]
#find all id's that exist more than once
non_unique<-as.data.frame(table(dat$id))
non_unique<-non_unique[non_unique$Freq>1,]
dat<-dat[dat$id %in% as.character(non_unique[,1]),]
dat
id V1 V2
1 100 A NA
2 100 B NA
引起的。因为如果 while(!uriTask.isSuccessful);
失败,这可能会导致无限循环。
我建议使用任务链(使用 continueWith
、continueWithTask
或 onSuccessTask
方法),以便更容易发现错误并且不会导致混乱的听众。
uriTask