1
我想排序一個iCollection的iBeacon對象,但只要代碼運行它會引發異常。我試圖運行的代碼如下。它工作正常,沒有任何排序或排序,但我需要能夠集合在接近進行排序,如圖所示(以最低的接近第一即1接近相等):Xamarin Android - 排序iBeacon iCollection導致異常
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
}
}
}
這裏是個例外:
[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
任何想法如何我可以得到正確的集合請正確?
我在AltBeacon庫中看到了同樣的問題。我認爲它與從JavaCollection到.NET ICollection的類型轉換有關,但我仍在尋找。 – chrisriesgo 2014-10-07 19:00:30
我得到同樣的東西。非常奇怪。無論是Xamarin錯誤還是AltBeacon庫中的競態條件,我都認爲。 – Oenotria 2015-08-27 15:44:53