gpt4 book ai didi

android - Xamarin Android - 排序 iBeacon iCollection 导致异常

转载 作者:行者123 更新时间:2023-11-30 02:37:50 25 4
gpt4 key购买 nike

我正在尝试对 iBeacon 对象的 iCollection 进行排序,但是一旦代码运行,它就会抛出异常。我试图运行的代码如下。它在没有任何排序或排序的情况下工作正常,但我需要能够根据接近度对集合进行排序,如图所示(首先接近度最低,即接近度等于 1):

async void RangingBeaconsInRegion(object sender, RangeEventArgs e)
{

if (e.Beacons.Count > 0)
{
var orderedBeacons = e.Beacons.OrderBy(b => b.Proximity); //this causes the problem

foreach (var beacon1 in orderedBeacons)
{
//do all my stuff here on my ordered beacons
}
}
}

异常(exception)情况:

[mono] Unhandled Exception:
[mono] System.ArgumentException: 'jmethod' must not be IntPtr.Zero.
[mono] Parameter name: jmethod
[mono] at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod) [0x00000] in <filename unknown>:0
[mono] at Android.Runtime.JavaCollection`1[RadiusNetworks.IBeaconAndroid.IBeacon].CopyTo (RadiusNetworks.IBeaconAndroid.IBeacon[] array, Int32 array_index) [0x00000] in <filename unknown>:0
[mono] at System.Linq.Enumerable.ToArray[IBeacon] (IEnumerable`1 source) [0x00000] in <filename unknown>:0
[mono] at System.Linq.QuickSort`1[RadiusNetworks.IBeaconAndroid.IBeacon]..ctor (IEnumerable`1 source, System.Linq.SortContext`1 context) [0x00000] in <filename unknown>:0
[mono] at System.Linq.QuickSort`1+<Sort>c__Iterator0[RadiusNetworks.IBeaconAndroid.IBeacon].MoveNext () [0x00000] in <filename unknown>:0

请问我如何才能正确订购该系列?

最佳答案

这应该适合您。让我知道进展如何。

var allBeacons = new List<Beacon>();

foreach(var b in e.Beacons)
{
allBeacons.Add(b);
}

var orderedBeacons = allBeacons.OrderBy(b => b.Proximity);

关于android - Xamarin Android - 排序 iBeacon iCollection 导致异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26217579/

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