Android Studio Firebase在路径中无效的令牌

发布于 2025-02-09 11:24:37 字数 2767 浏览 0 评论 0原文

我遇到了一个错误:

2022-06-20 16:32:37.238 6195-6195/com.example.couponsapp e/firebase:错误获取数据 java.lang.exception:路径中无效的令牌 请访问com.google.firebase.database.connection.connection.persistentConnectionImpl.lambda $获取$ 0 $ com-google-firebase-firebase-database-connection-connection-persistentConnectionmpl(PersistentConnectionMimpl.java:425) 在com.google.firebase.database.connection.connection.persistentConnectionImpl $ externalsyntheticlambda2.onresponse(未知来源:6) 在com.google.firebase.database.connection.connection.persistentConnectionImpl $ 6.NResponse(PersistentConnectionImpl.java:1292) 在com.google.firebase.database.connection.connection.persistentConnectionImpl.ondatamessage(PersistentConnectionImpl.java:496) 在com.google.firebase.database.connection.connection.ondatamessage(Connection.java:167) 在com.google.firebase.database.connection.connection.onmessage(Connection.java:131) 在com.google.firebase.database.connection.websocketconnection.appendframe(websocketConnection.java:259) 在com.google.firebase.database.connection.websocketconnection.handleincomingframe(webSocketConnection.java:306) 在com.google.firebase.database.connection.websocketConnection.Access $ 500(WebSocketConnection.java:34) 在com.google.firebase.database.connection.websocketConnection $ wsclienttubesock $ 2. run(websocketConnection.java:86) 在java.util.concurrent.executors $ runnableDapter.call(executors.java:462) 在java.util.concurrent.futuretask.run(futuretask.java:266) 在java.util.concurrent.scheduledthreadpoolexecutor $ scheduledfuturetask.run(steguledthreadpoolexecutor.java:301) at Java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1167) at Java.util.concurrent.threadpoolexecutor $ worker.run(threadpoolexecutor.java:641) 在java.lang.thread.run(thread.java:923)

每当我运行以下代码时,请访问路径中

mDatabase.child("users").child(uuid).get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<DataSnapshot> task) {
        if (!task.isSuccessful()) {
            Log.e("firebase", "Error getting data", task.getException());
        }
        else {
            String studentID = String.valueOf(task.getResult().getValue());
            studentBox.setText(studentID);
        }

:这很奇怪,因为UUID只是生成的标准firebase生成的uuid:

-n5 -hbhtttt0yumo7ebxd,

我都尝试了所有在线解决方案和所有在线解决方案和所有在线解决方案,仅在删除.Child(UUID)之后才能使用,但是我无法获得所需的数据。

这是JSON:

  "users": {
    "-N5-HbHttT0yUMO7ebxD": {
      "studentBal": 4000,
      "studentID": "P-2329",
      "studentName": "Hello World"
    },
    "HaMeP1-273299386": {
      "studentBal": 2800,
      "studentID": "P-1329",
      "studentName": "Ha Me"
    }
  }
}

I'm getting an error of:

2022-06-20 16:32:37.238 6195-6195/com.example.couponsapp E/firebase: Error getting data
java.lang.Exception: Invalid token in path
at com.google.firebase.database.connection.PersistentConnectionImpl.lambda$get$0$com-google-firebase-database-connection-PersistentConnectionImpl(PersistentConnectionImpl.java:425)
at com.google.firebase.database.connection.PersistentConnectionImpl$$ExternalSyntheticLambda2.onResponse(Unknown Source:6)
at com.google.firebase.database.connection.PersistentConnectionImpl$6.onResponse(PersistentConnectionImpl.java:1292)
at com.google.firebase.database.connection.PersistentConnectionImpl.onDataMessage(PersistentConnectionImpl.java:496)
at com.google.firebase.database.connection.Connection.onDataMessage(Connection.java:167)
at com.google.firebase.database.connection.Connection.onMessage(Connection.java:131)
at com.google.firebase.database.connection.WebsocketConnection.appendFrame(WebsocketConnection.java:259)
at com.google.firebase.database.connection.WebsocketConnection.handleIncomingFrame(WebsocketConnection.java:306)
at com.google.firebase.database.connection.WebsocketConnection.access$500(WebsocketConnection.java:34)
at com.google.firebase.database.connection.WebsocketConnection$WSClientTubesock$2.run(WebsocketConnection.java:86)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)

In path whenever I run the following code:

mDatabase.child("users").child(uuid).get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<DataSnapshot> task) {
        if (!task.isSuccessful()) {
            Log.e("firebase", "Error getting data", task.getException());
        }
        else {
            String studentID = String.valueOf(task.getResult().getValue());
            studentBox.setText(studentID);
        }

This is weird because the UUID is only the standard firebase generated UUID:

-N5-HbHttT0yUMO7ebxD

I have tried all online solutions and the code only worked after I removed the .child(uuid), but then I can't get the data I need.

Here is the JSON:

  "users": {
    "-N5-HbHttT0yUMO7ebxD": {
      "studentBal": 4000,
      "studentID": "P-2329",
      "studentName": "Hello World"
    },
    "HaMeP1-273299386": {
      "studentBal": 2800,
      "studentID": "P-1329",
      "studentName": "Ha Me"
    }
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔梦 2025-02-16 11:24:37

您正在使用错误的方法来存储用户的数据。而不是.child(uuid)请使用.Child(currentUserid)保存数据。 currentUserid也是所有用户的唯一ID,因此,在获得数据时可以通过mdatabase.Child(“ users”)。子(currentuserid).get().get()。 ....)等等,您可以做到。

You are using a wrong method to store a data of a user. Instead of .child(UUID) kindly use the .child(currentUserID) to save data. CurrentUserId is also a unique ID for all user so while getting the data use can pass as mDatabase.child("users").child(currentUserID).get().addOnCompleteListener(......) and so on in this way u can do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文