-3

i having this error Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. And anyone here know what should i do to fix it , this is my code below and the error code is this ddlHour2.Items.FindByText(str(0)).Selected = True

Public Class dbconn
Inherits System.Web.UI.Page


Dim path As New FilePath
Dim regval As New RegistrySettings(True)
Dim encr As Encryption = New Encryption
Dim EHRMSPath As String
Dim WEBPath As String
Dim APPSETTINGPath As String
Dim WSERVICEPath As String
Dim instance As ObjectDisposedException
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If Session("UserId") = "" Or (Session("UserType") <> 3 And Session("UserType") <> 1) Then
        Response.Redirect("redirect_admin.aspx?url=login_admin.aspx")
    End If

    EHRMSPath = path.LocatePath(1)
    WEBPath = path.LocatePath(2)
    APPSETTINGPath = path.LocatePath(4)
    WSERVICEPath = path.LocatePath(5)

    If Not IsPostBack Then

        ddlHour.Enabled = False
        ddlMin.Enabled = False
        ddlHour2.Enabled = False
        ddlMin2.Enabled = False
        ddlHour3.Enabled = False
        ddlMin3.Enabled = False

        MoveRegValToScreen()
        'ddlDtFormat.Items.FindByText(Trim(Session("DateFormat"))).Selected = True
        fillDdlHourMin()

        If File.Exists(WSERVICEPath) <> False Then

            Dim strAutoApprSchedule As String
            Dim strSupEmailSchedule As String
            Dim strSupEmailSchedule2 As String
            Dim strSupEmailSchedule3 As String
            Dim strAutoEntlSchedule As String

            strAutoApprSchedule = path.getWSERVICE(1, WSERVICEPath)
            strSupEmailSchedule = path.getWSERVICE(2, WSERVICEPath)
            strSupEmailSchedule2 = path.getWSERVICE(6, WSERVICEPath)
            strSupEmailSchedule3 = path.getWSERVICE(7, WSERVICEPath)
            strAutoEntlSchedule = path.getWSERVICE(3, WSERVICEPath)

            If Not strAutoApprSchedule = "" Then
                Dim str() As String = Split(strAutoApprSchedule, ".")
                ddlApprHr.Items.FindByText(str(0)).Selected = True
                ddlApprMin.Items.FindByText(str(1)).Selected = True
            End If

            If Not strSupEmailSchedule = "" Then
                Dim str() As String = Split(strSupEmailSchedule, ".")
                ddlHour.Items.FindByText(str(0)).Selected = True
                ddlMin.Items.FindByText(str(1)).Selected = True

                CheckBoxETime1.Checked = True
                ddlHour.Enabled = True
                ddlMin.Enabled = True
            End If

            If Not strAutoEntlSchedule = "" Then
                Dim str() As String = Split(strAutoEntlSchedule, ".")
                ddlEntlHr.Items.FindByText(str(0)).Selected = True
                ddlEntlMin.Items.FindByText(str(1)).Selected = True
            End If

            'sini

            If Not strSupEmailSchedule2 = "" Then
                Dim strTime As String = regval.strSupEmailSchedule2
                Dim str() As String = Split(strTime, ".")
                ddlHour2.Items.FindByText(str(0)).Selected = True
                ddlMin2.Items.FindByText(str(1)).Selected = True

                CheckBoxETime2.Checked = True
                ddlHour2.Enabled = True
                ddlMin2.Enabled = True
            End If
            If Not strSupEmailSchedule3 = "" Then
                Dim strTime As String = regval.strSupEmailSchedule3
                Dim str() As String = Split(strTime, ".")
                ddlHour3.Items.FindByText(str(0)).Selected = True
                ddlMin3.Items.FindByText(str(1)).Selected = True

                CheckBoxETime3.Checked = True
                ddlHour3.Enabled = True
                ddlMin3.Enabled = True
            End If
        End If
    End If
End Sub
Ooi Jian
  • 7
  • 5

1 Answers1

0

seems like the method you are using returns NULL i.e. "FindByText" and then you are accessing its sub property i.e. "Selected". So if the preceding method returns NULL it is giving the error.

Try This

If Not ddlHour2.Items.FindByText(str(0)) is nothing then
ddlApprHr.Items.FindByText(str(0)).Selected = True
End if