gpt4 book ai didi

Android Firebase 两个节点 updateChildren,失败 : DatabaseError: Invalid token in path

转载 作者:行者123 更新时间:2023-11-30 00:30:47 26 4
gpt4 key购买 nike

我正在尝试在 Firebase 中创建一个新数据并根据用户对其进行更新,但在尝试建立关系时我总是遇到错误。我附上了节点的图像和一些代码。 enter image description here

和代码:

        // Create a reference that point to transportador and the currenUser
DatabaseReference wayPointRef;
// Create a reference to the vehicle node db
final DatabaseReference refVehicle = mDatabase.getReference("vehiculo");
// Create a reference to the transportador node db
final DatabaseReference refTrans = mDatabase.getReference("transportador");
// Take the key create of the new vehicle
final String key = refVehicle.push().getKey();
// Show the key
KLog.a("key of the new vehicle : " + key);

mainHandler.post(new Runnable() {
@Override
public void run() {
sweetAlertDialog = new SweetAlertDialog(actvty, SweetAlertDialog.PROGRESS_TYPE);
sweetAlertDialog.getProgressHelper()
.setBarColor(Color.parseColor("#00C800"));
sweetAlertDialog.setTitleText("xxxxxxx");
sweetAlertDialog.setContentText("Creando Vehiculo");
sweetAlertDialog.setCancelable(false);
sweetAlertDialog.show();
}
});
wayPointRef = refTrans.child(currentUserKey).child("vehiculos");
vehicle = new Vehiculo(key, vehiculo, carroceria, placa, modelo, pesoMax, volumen, largo,
alto, ancho);
Map<String, Object> vehicleValues = vehicle.toMap();

Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put(refVehicle + "/" + key, vehicleValues);
childUpdates.put("/" + "vehiculos/" + key, vehicleValues);
//mDatabase.updateChildren(childUpdates);

final String finalCurrentUserKey = currentUserKey;
wayPointRef.updateChildren(childUpdates, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(final DatabaseError databaseError, DatabaseReference databaseReference) {
if (databaseError != null){

这是日志答案:

06-08 21:09:56.794 7671-9043/xxxxxxxxxx W/RepoOperation: updateChildren at /transportador/lONs9g5nLON1Ql4Fs24REuz8T2z2/vehiculos failed: DatabaseError: Invalid token in path 06-08 21:09:56.854 7671-7671/xxxxxxxxxxxx A/TAG: [ (FirebaseServiceManagerT.java:277)#run ] Param[0] = createVehicle:failed Param1 = -999

最佳答案

最有可能发生的情况是您的 key 包含一些 Firebase 不允许您在节点 key 中包含的字符。

即:

  • >。 (期间)
  • $(美元符号)
  • [(左方括号)
  • ](右方括号)
  • #(井号或井号)
  • /(正斜杠)

一个简单的 String.replace() 应该可以在这里工作。

关于Android Firebase 两个节点 updateChildren,失败 : DatabaseError: Invalid token in path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44448306/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com