目前正在Unity中开发应用程序,其中我需要获得正在使用的前3个产品。我在检索数据时使用以下代码:
FirebaseDatabase.DefaultInstance
.GetReference ("Products").OrderByChild("used").LimitToFirst(3)
.ValueChanged += HandleValueChanged;
}
void HandleValueChanged(object sender, ValueChangedEventArgs args) {
if (args.DatabaseError != null) {
Debug.LogError (args.DatabaseError.Message);
return;
}
它无效,我收到此错误:
System.NullReferenceException: Object reference not set to an instance of an object
at ShowProducts.HandleValueChanged (System.Object sender, Firebase.Database.ValueChangedEventArgs args) [0x000be] in C:\Users\jorren\Documents\JKL\Assets\Scripts\ShowProducts.cs:697
at Firebase.Database.Internal.Core.ValueEventRegistration.FireEvent (Firebase.Database.Internal.Core.View.DataEvent eventData) [0x00000] in <filename unknown>:0
at Firebase.Database.Internal.Core.View.DataEvent.Fire () [0x00000] in <filename unknown>:0
at Firebase.Database.Internal.Core.View.EventRaiser+Runnable30.Run () [0x00000] in <filename unknown>:0
at Firebase.Database.DotNet.DotNetPlatform+SynchronizationContextTarget+<PostEvent>c__AnonStorey0.<>m__0 (System.Object x) [0x00000] in <filename unknown>:0
at Firebase.Unity.UnitySynchronizationContext+SynchronizationContextBehavoir+<Start>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0
UnityEngine.Debug:Log(Object)
Firebase.Unity.<Start>c__Iterator0:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
但是当我使用LimitToLast()时,它工作正常
非常感谢!