Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 极限火源第一(统一)_C#_Firebase_Unity3d_Firebase Realtime Database - Fatal编程技术网

C# 极限火源第一(统一)

C# 极限火源第一(统一),c#,firebase,unity3d,firebase-realtime-database,C#,Firebase,Unity3d,Firebase Realtime Database,目前正在Unity中开发一个应用程序,其中我需要获得正在使用的前3个产品。我正在使用以下代码检索数据: FirebaseDatabase.DefaultInstance .GetReference ("Products").OrderByChild("used").LimitToFirst(3) .ValueChanged += HandleValueChanged; } void HandleValueChanged(object sender

目前正在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:对象引用未设置为对象的实例
在C:\Users\jorren\Documents\JKL\Assets\Scripts\ShowProducts.cs:697中的ShowProducts.HandleValueChanged(System.Object sender,Firebase.Database.ValueChangedEventArgs)[0x000be]中
位于:0中的Firebase.Database.Internal.Core.ValueEventRegistration.FireEvent(Firebase.Database.Internal.Core.View.DataEvent eventData)[0x00000]处
位于:0中的Firebase.Database.Internal.Core.View.DataEvent.Fire()[0x00000]处
在Firebase.Database.Internal.Core.View.EventRaiser+Runnable30.Run()[0x00000]中:0
在Firebase.Database.DotNet.DotNetPlatform+SynchronizationContextTarget+c__AnonStorey0.m_u 0(System.Object x)[0x00000]中:0
在Firebase.Unity.UnitySynchronizationContext+SynchronizationContextBehavoir+c__迭代器0.MoveNext()[0x00000]中:0
调试:日志(对象)
Firebase.Unity.c__迭代器0:MoveNext()
UnityEngine.SetupCorroutine:InvokeMoveNext(IEnumerator,IntPtr)

但是当我使用LimitToLast()时,它工作得很好


非常感谢

这是一个常见的
NullReferenceException
,这可能意味着您的数据库中的产品少于3个。我的数据库中有4个产品:(如果
.GetReference(“产品”).OrderByChild(“已使用”),请使用调试器进行检查)
返回所有4个产品。可能某些筛选条件阻止返回所有产品。我在尝试时遇到了相同的错误。GetReference(“产品”).OrderByChild(“已使用”),因此
FirebaseDatabase.DefaultInstance
为空?