In my project i need contunistly read barcode and put them in a list. But while i trying it its always giving me NullReferenceException but i didn't get it. When i check it in debug i can see it have a string value but while trying put it to list its always giving me that error. Its my code for Scan and take data:
List<HoldMyString> mylist;
HoldMyString hold;
private void ZXingScannerView_OnScanResult(ZXing.Result result)
{
Device.BeginInvokeOnMainThread(() =>
{
hold.HoldString = result.Text; // HoldString is taking string value
mylist.Add(hold);
});
}
How i can put my datas in to my list contunistly. Thanks for help!
I was able to reproduce the same error with yours.
You could use the code below.
HoldMyString:
public class HoldMyString
{
public string HoldString { get; set; }
}
Code for Scan and take data:
List<HoldMyString> mylist=new List<HoldMyString>();
HoldMyString hold = new HoldMyString();
private void Handle_OnScanResult(ZXing.Result result)
{
Device.BeginInvokeOnMainThread(() =>
{
hold.HoldString = result.Text; // HoldString is taking string value
mylist.Add(hold);
});
}
For more details about how to get the barcodes, you could check the thread i done before. How to embed ZXing scanner in PageRenderer/Fragment/View into Xamarin.Forms ContentPage?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.