我想删除特定节点内的所有数据,而不知道特定的id's.我写了一些按钮点击内的函数:
val dbref = FirebaseDatabase.getInstance().reference.child("Message")
dbref.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
for (data in snapshot.children) {
data.ref.removeValue()
}
}
override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
})
字符串
每当我点击按钮时,应用程序会在几秒钟后崩溃,并显示以下堆栈跟踪:
2023-10-24 15:08:55.651 15854-15878 OpenGLRenderer com.example.myapplication E Unable to match the desired swap behavior.
2023-10-24 15:08:58.479 571-1625 TaskPersister system_server E File error accessing recents directory (directory doesn't exist?).
2023-10-24 15:09:24.970 15854-15881 RunLoop com.example.myapplication E Firebase Database encountered an OutOfMemoryError. You may need to reduce the amount of data you are syncing to the client (e.g. by using queries or syncing a deeper path). See https://firebase.google.com/docs/database/ios/structure-data#best_practices_for_data_structure and https://firebase.google.com/docs/database/android/retrieve-data#filtering_data
java.lang.OutOfMemoryError: Failed to allocate a 16 byte allocation with 692344 free bytes and 676KB until OOM, target footprint 201326592, growth limit 201326592; giving up on allocation because <1% of heap free after GC.
at java.lang.Long.valueOf(Long.java:1252)
at com.google.firebase.database.core.WriteTree$1.evaluate(WriteTree.java:238)
at com.google.firebase.database.core.WriteTree$1.evaluate(WriteTree.java:234)
at com.google.firebase.database.core.WriteTree.layerTree(WriteTree.java:433)
at com.google.firebase.database.core.WriteTree.calcCompleteEventCache(WriteTree.java:243)
at com.google.firebase.database.core.SyncTree.calcCompleteEventCache(SyncTree.java:999)
at com.google.firebase.database.core.Repo.setValue(Repo.java:467)
at com.google.firebase.database.DatabaseReference$1.run(DatabaseReference.java:290)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
2023-10-24 15:09:26.347 15854-15881 RunLoop com.example.myapplication E Firebase Database encountered an OutOfMemoryError. You may need to reduce the amount of data you are syncing to the client (e.g. by using queries or syncing a deeper path). See https://firebase.google.com/docs/database/ios/structure-data#best_practices_for_data_structure and https://firebase.google.com/docs/database/android/retrieve-data#filtering_data
java.lang.OutOfMemoryError: Failed to allocate a 426856 byte allocation with 163360 free bytes and 159KB until OOM, target footprint 201326592, growth limit 201326592
at java.util.Arrays.copyOf(Arrays.java:3553)
at java.util.Arrays.copyOf(Arrays.java:3522)
at java.util.ArrayList.grow(ArrayList.java:244)
at java.util.ArrayList.grow(ArrayList.java:251)
at java.util.ArrayList.add(ArrayList.java:461)
at java.util.ArrayList.add(ArrayList.java:474)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.drainTo(ScheduledThreadPoolExecutor.java:1280)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.drainTo(ScheduledThreadPoolExecutor.java:1263)
at java.util.concurrent.ThreadPoolExecutor.drainQueue(ThreadPoolExecutor.java:862)
at java.util.concurrent.ThreadPoolExecutor.shutdownNow(ThreadPoolExecutor.java:1425)
at java.util.concurrent.ScheduledThreadPoolExecutor.shutdownNow(ScheduledThreadPoolExecutor.java:876)
at com.google.firebase.database.android.AndroidPlatform$1.handleException(AndroidPlatform.java:106)
at com.google.firebase.database.core.utilities.DefaultRunLoop$1.afterExecute(DefaultRunLoop.java:89)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
2023-10-24 15:09:26.349 15854-15882 AndroidRuntime com.example.myapplication E FATAL EXCEPTION: TubeSockReader-1
Process: com.example.myapplication, PID: 15854
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@a687cc3[Not completed] rejected from com.google.firebase.database.core.utilities.DefaultRunLoop$1@522e072[Shutting down, pool size = 1, active threads = 1, queued tasks = 463677, completed tasks = 11460]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2082)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:842)
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:345)
at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:569)
at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:712)
at com.google.firebase.database.connection.WebsocketConnection$WSClientTubesock.onError(WebsocketConnection.java:106)
at com.google.firebase.database.tubesock.WebSocket.runReader(WebSocket.java:432)
at com.google.firebase.database.tubesock.WebSocket.access$000(WebSocket.java:47)
at com.google.firebase.database.tubesock.WebSocket$2.run(WebSocket.java:143)
at java.lang.Thread.run(Thread.java:1012)
2023-10-24 15:09:26.349 15854-15854 AndroidRuntime com.example.myapplication E FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 15854
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@43fb527[Not completed] rejected from com.google.firebase.database.core.utilities.DefaultRunLoop$1@522e072[Shutting down, pool size = 1, active threads = 1, queued tasks = 463677, completed tasks = 11460]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2082)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:842)
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:345)
at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:569)
at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:712)
at com.google.firebase.database.core.utilities.DefaultRunLoop.scheduleNow(DefaultRunLoop.java:105)
at com.google.firebase.database.core.Repo.scheduleNow(Repo.java:304)
at com.google.firebase.database.DatabaseReference.setValueInternal(DatabaseReference.java:286)
at com.google.firebase.database.DatabaseReference.setValue(DatabaseReference.java:159)
at com.google.firebase.database.DatabaseReference.removeValue(DatabaseReference.java:437)
at com.example.myapplication.MainActivity$onClick$1.onDataChange(MainActivity.kt:52)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:75)
at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8177)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
---------------------------- PROCESS ENDED (15854) for package com.example.myapplication ----------------------------
2023-10-24 15:09:26.396 30365-30388 OpenGLRenderer com.example.currencyexchange E Unable to match the desired swap behavior.
2023-10-24 15:09:26.417 419-419 BpTransact...edListener surfaceflinger E Failed to transact (-32)
2023-10-24 15:09:29.899 571-1625 TaskPersister system_server E File error accessing recents directory (directory doesn't exist?).
2023-10-24 15:10:29.373 571-767 ClipboardService system_server E Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:10:29.378 571-768 ClipboardService system_server E Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:11:24.686 571-767 ClipboardService system_server E Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:11:24.688 571-768 ClipboardService system_server E Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:11:28.275 571-767 ClipboardService system_server E Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:11:28.401 571-767 ClipboardService system_server E Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:11:52.889 5250-10954 WakeLock com.google.android.gms.persistent E GCM_HB_ALARM release without a matched acquire!
2023-10-24 15:11:57.631 16102-16102 gle.android.tts pid-16102 E Not starting debugger since process cannot load the jdwp agent.
2023-10-24 15:11:58.051 16149-16149 equicksearchbox pid-16149 E Not starting debugger since process cannot load the jdwp agent.
2023-10-24 15:11:58.629 5250-5345 bwfc com.google.android.gms.persistent E Phenotype API error. Event # edax@b9088f2a, EventCode: 5 [CONTEXT service_id=51 ]
bwdx: 29501: Stale snapshot for com.google.android.libraries.search.googleapp.device#com.google.android.googlequicksearchbox(change count changed - expected 10 but was 9)
at bwfg.b(:com.google.android.gms@[email protected] (190800-535401451):16)
at bwff.g(:com.google.android.gms@[email protected] (190800-535401451):0)
at bwfc.e(:com.google.android.gms@[email protected] (190800-535401451):4)
at bwfc.f(:com.google.android.gms@[email protected] (190800-535401451):2)
at avsy.eo(:com.google.android.gms@[email protected] (190800-535401451):1)
at avtf.run(:com.google.android.gms@[email protected] (190800-535401451):14)
at dfhf.run(:com.google.android.gms@[email protected] (190800-535401451):2)
at aced.c(:com.google.android.gms@[email protected] (190800-535401451):6)
at aced.run(:com.google.android.gms@[email protected] (190800-535401451):8)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at acjn.run(:com.google.android.gms@[email protected] (190800-535401451):0)
at java.lang.Thread.run(Thread.java:1012)
2023-10-24 15:11:58.636 16102-16145 tflite pid-16102 E third_party/tensorflow/lite/core/subgraph.cc:903 tensor.data.raw != nullptr was not true.
2023-10-24 15:11:59.247 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.247 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.248 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.248 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.249 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.253 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.254 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.255 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.255 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.256 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.256 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.256 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_en-US is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.256 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.257 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.275 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.275 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.276 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.277 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.277 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.278 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.278 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.279 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.279 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.280 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.281 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.282 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_en-US is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.283 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.283 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.338 5250-12348 NanoAppLogging com.google.android.gms.persistent E Failed to begin contexthub communication
2023-10-24 15:11:59.578 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_en-US is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.582 1559-2100 SP.Service.AiAi com.google.android.as E captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.763 5376-5455 MDD com.google.android.gms E FileGroupManager: Trying to add expired group enpromo-state-config.
2023-10-24 15:12:00.053 5376-25996 Pay com.google.android.gms E [Migration operation] Active tapandpay account not found! [CONTEXT service_id=198 ]
型
当我想向数据库中添加新值时,我实现了一些错误,所以我有多个具有相同值的键,而不是只有一个。现在,我只想“擦除”这个节点。
2条答案
按热度按时间vaj7vani1#
尝试以下操作...
字符串
a5g8bdjr2#
您将得到以下错误:
Firebase数据库遇到OutOfMemoryError。您可能需要减少同步到客户端的数据量(例如,通过使用查询或同步更深的路径)。
因为您尝试读取的
Message
节点包含更多的数据,可以放入您的内存,因此出现错误。除此之外,不需要读取节点来删除它。您可以直接在所需节点上调用DatabaseReference#removeValue():
字符串
当您执行重复操作时,永远不要忽略潜在的错误。