Problems with "System.NullReferenceException: Object reference not set to an instance of an object."

RodrigosjcRodrigosjc Member ✭✭

Hello, I'm having a problem saving a data while doing a QRcode reading that complains about this error. Someone could help. Thank you
Follow the code below:

Answers

  • RodrigosjcRodrigosjc Member ✭✭

    When doing the debugger in the code as shown in the data.length (date is given) is null, but as it does not show that null, show a value that the application can not close or be hang. Thank you

  • ColeXColeX Member, Xamarin Team Xamurai
    edited March 25

    The property Length belongs to string class , here you are calling null.Length , so the exception throws.

    Check your code where the method GetDateFromHex locates and what's the value of date you populate.

    Or modify the logic to avoid the exception .

     private string GetDateFromHex(string date)
        {
            var output = string.Empty;  
    
            if (date == null)
                return output;   //protection
    
           /// xxxx
    
        }
    
  • RodrigosjcRodrigosjc Member ✭✭
    edited March 25

    Hello ColeX, I got to do what you did the GetDateFromHex error continues the error, but to make life easier I'm sending these codes to understand the path where it goes in xarin forms




  • ColeXColeX Member, Xamarin Team Xamurai

    Refer https://stackoverflow.com/a/44031307/8187800

    Try to use DateTime.ParseExact instead , and check the date time format.

    For example , if the string is 17/5/2017 19:10:00 , the format you set should be dd/M/yyyy HH:mm:ss .

Sign In or Register to comment.