我正在使用Zxing.Mobile扫描我的monodroid应用程序中的条形码。我正在使用Xamarin。根据他们的文档,下面的代码行应该有效:
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
scanner.Scan().ContinueWith(t => {
if (t.Result != null)
Console.WriteLine("Scanned Barcode: " + t.Result.Text);
});
但是我收到了以下错误:
The type 'Zxing.Mobile.MobileBarcodeScanner()' does not contain a constructor that takes '0' arguments
我知道为什么会出现这个错误,我怎么能摆脱它?提前谢谢。
答案 0 :(得分:2)
如上所述,您需要提供Context,他只是没有将上下文放入构造函数中。嘿。因此造成混乱。
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this.Context);
scanner.Scan().ContinueWith(t => {
if (t.Result != null)
Console.WriteLine("Scanned Barcode: " + t.Result.Text);
});`
答案 1 :(得分:1)
这对我有用
async void HandleBarcodeButtonClick(object sender, EventArgs e)
{
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
string barcode = string.Empty;
await scanner.Scan().ContinueWith(t =>
{
if (t.Result != null)
barcode = t.Result.Text;
});
}
答案 2 :(得分:0)
构造函数需要多于0
个参数。来自here:
//NOTE: On Android you MUST pass a Context into the Constructor!
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
scanner.Scan().ContinueWith(t => {
if (t.Result != null)
Console.WriteLine("Scanned Barcode: " + t.Result.Text);
});