How to solve {System.NullReferenceException: Object reference not set to an instance of an object.}

SwagatikaSwagatika Member ✭✭✭

I want do design a QR code scanner app but whenever i click the i am getting error-{System.NullReferenceException: Object reference not set to an instance of an object.}.Below is my code.


Best Answers

Answers

  • SwagatikaSwagatika Member ✭✭✭

    Any suggestion please?

  • SwagatikaSwagatika Member ✭✭✭

    In MainPage result is getting null and in catch block throws line i am getting exception.

  • SwagatikaSwagatika Member ✭✭✭

    yes i add [assembly: Xamarin.Forms.Dependency(typeof(QRcodescanner2.New.QRCodescanner))]
    but again i am getting the same error. and in this line {var result = await scanner.ScanAsync(); } result is coming null.

  • JohnHardmanJohnHardman GBUniversity mod

    @Swagatika said:
    yes i add [assembly: Xamarin.Forms.Dependency(typeof(QRcodescanner2.New.QRCodescanner))]
    but again i am getting the same error. and in this line {var result = await scanner.ScanAsync(); } result is coming null.

    result being null would not result in an exception in the code posted above.
    If you put a breakpoint on that line, is scanner null? That would make more sense and would be the result of not registering the dependency service correctly.

  • SwagatikaSwagatika Member ✭✭✭

    In scanner is not coming null only in the result line it is coming null and that is directly entering to catch block. and throwing exception.

  • JohnHardmanJohnHardman GBUniversity mod

    @Swagatika said:
    In scanner is not coming null only in the result line it is coming null and that is directly entering to catch block. and throwing exception.

    Sorry, I'm not sure what you are saying here.

    Is scanner null, or is scanner not null?

Sign In or Register to comment.