IStatusListenerImplementor

IStatusListenerImplementor

我在Xamarain.Android应用程序中为xamarin使用EMDK。我收到此错误:


无法从本机句柄0x1d200001(key_handle 0x426eae90)激活类型为Symbol.XamarinEMDK.Barcode.Scanner + IStatusListenerImplementor的实例。


该错误是随机发生的。

在下面的详细日志中查找。请协助解决这个问题

System.NotSupportedException: Unable to activate instance of type Symbol.XamarinEMDK.Barcode.Scanner+IStatusListenerImplementor from native handle 0x1d200001 (key_handle 0x41b8ad20). ---> System.MissingMethodException: No constructor found for Symbol.XamarinEMDK.Barcode.Scanner+IStatusListenerImplementor::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
  at Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
  at --- End of managed Java.Lang.Error stack trace ---
  at java.lang.Error: Java callstack:
  at at mono.com.symbol.emdk.barcode.Scanner_StatusListenerImplementor.n_onStatus(Native Method)
  at at mono.com.symbol.emdk.barcode.Scanner_StatusListenerImplementor.onStatus(Scanner_StatusListenerImplementor.java:30)
  at at com.symbol.emdk.barcode.StatusCallbackInternal$StatusCallbackThread.run(StatusCallbackInternal.java:73)
  at --- End of managed Java.Lang.Error stack trace ---
  at java.lang.Error: Java callstack:
  at at mono.com.symbol.emdk.barcode.Scanner_StatusListenerImplementor.n_onStatus(Native Method)
  at at mono.com.symbol.emdk.barcode.Scanner_StatusListenerImplementor.onStatus(Scanner_StatusListenerImplementor.java:30)
  at at com.symbol.emdk.barcode.StatusCallbackInternal$StatusCallbackThread.run(StatusCallbackInternal.java:73)
  --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateProxy (System.Type type, IntPtr handle, JniHandleOwnership transfer) [0x00058] in <filename unknown>:0
  at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) [0x00138] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) [0x001b0] in <filename unknown>:0
  at Java.Lang.Object.GetObject (IntPtr handle, JniHandleOwnership transfer, System.Type type) [0x000e5] in <filename unknown>:0
  at Java.Lang.Object._GetObject[T] (IntPtr handle, JniHandleOwnership transfer) [0x0001a] in <filename unknown>:0
  at Java.Lang.Object.GetObject[T] (IntPtr handle, JniHandleOwnership transfer) [0x00000] in <filename unknown>:0
  at Java.Lang.Object.GetObject[T] (IntPtr jnienv, IntPtr handle, JniHandleOwnership transfer) [0x00006] in <filename unknown>:0
  at Symbol.XamarinEMDK.Barcode.Scanner+IStatusListenerInvoker.n_OnStatus_Lcom_symbol_emdk_barcode_StatusData_ (IntPtr jnienv, IntPtr native__this, IntPtr native_p0) [0x00000] in <filename unknown>:0
  at at (wrapper dynamic-method) System.Object:043283ed-110f-43b7-811b-51b1dfa39e65 (intptr,intptr,intptr)

最佳答案

仅添加此内容,以防将来有人偶然发现它

不知道为什么会收到该错误,但这是一个无需添加IStatusListenerImplementor接口的实现即可工作的代码示例。

private void SetupEmdkBarcodeScanner
{
    var emdkBarcodeManager = (Symbol.XamarinEMDK.Barcode.BarcodeManager)emdkManager.GetInstance(EMDKManager.FEATURE_TYPE.Barcode);
    var emdkBarcodeScanner = emdkBarcodeManager.GetDevice(BarcodeManager.DeviceIdentifier.Default);
    if(emdkBarcodeScanner.IsReadPending)
    {
        emdkBarcodeScanner.CancelRead();
    }
    emdkBarcodeScanner.Data += HandleReadEvent;
    emdkBarcodeScanner.Status += HandleStatusEvent;
}

private void HandleStatusEvent(object sender, Scanner.StatusEventArgs e)
{
    if (e.P0.State != StatusData.ScannerStates.Idle)
    {
        return;
    }

    lock (concurrentReadsLock)
    {
        Thread.Sleep(100);

        if (scanner.IsReadPending)
        {
            return;
        }

        emdkBarcodeScanner.Read();
    }
}

private void HandleReadEvent(object sender, Scanner.DataEventArgs e)
{
    if (e.P0.Result != ScannerResults.Success)
    {
        return
    }

    foreach (ScanDataCollection.ScanData data in e.P0.GetScanData())
    {
        string aimBarcodeData = data.Data; //here is your scanned barcode (e.g.: "]E00123456789123"
        //... your barcode processing code goes here //
    }
}


另外,不要忘记在最后处理:

emdkBarcodeScanner.CancelRead();
emdkBarcodeScanner.Disable();
//.. unsubscribe the event handlers
emdkBarcodeScanner.Dispose();
//...and finally release the EMDK to remove your application's exclusive access.
emdkBarcodeManager.Release(EMDKManager.FEATURE_TYPE.Barcode);

10-04 12:32