Object reference not set to an instance of an object.

Posted by: reflaherty on 8 September 2017, 1:18 pm EST

  • Posted 8 September 2017, 1:18 pm EST

    After I remove all of the characters from a cell, I get Null-Reference error when performing a GetValue on that cell.


    Below is the code:


    private static string GetSpreadStringValue(SheetView sv, int iRow, int iCol)


    {


    try


    {


    if (String.IsNullOrEmpty(sv.GetValue(iRow, iCol).ToString()) == true)


    {


    return "";


    }


    else


    {


    return sv.GetValue(iRow, iCol).ToString();


    }


    }


    catch (NullReferenceException ex)


    {


    ErrorHandling.LogError(ex, "Row: " + iRow.ToString() + " - Column: " + iCol.ToString());


    return "";


    }


    catch (Exception ex)


    {


    ErrorHandling.LogError(ex, "Row: " + iRow.ToString() + " - Column: " + iCol.ToString());


    return "";


    }


    }


     


    Below is in part the error message generated: 


    Error Type: NullReferenceException
    When: 6/20/2008 11:53:53 AM
    Description: Object reference not set to an instance of an object.
    Source: OrderWizProspects
    Stack Trace:    at OrderWizProspects.frmConvertProspectImport.GetSpreadStringValue(SheetView sv, Int32 iRow, Int32 iCol) in C:\Documents and Settings\REF.BLCC\My Documents\Visual Studio 2008\Projects\Windows\OrderWizNet\OrderWizProspects\frmConvertProspectImport.cs:line 51
    Target Site: System.String GetSpreadStringValue(FarPoint.Win.Spread.SheetView, Int32, Int32)

  • Replied 8 September 2017, 1:18 pm EST

    Hello,


    If an object is null, you can not call the ToString method. This is what is causing the exception. You should check the value returned by GetValue is not null before calling the ToString method.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels