Solved

Error: Object reference not set to an instance of an object.

Posted on 2012-04-05
2
184 Views
Last Modified: 2012-06-21
I have the following loop:

 
If fvShip.CurrentMode = FormViewMode.ReadOnly Then
            Dim bLinks() As LinkButton = {bLink, bLink1, bLink2, bLink3, bLink4}
            Dim lblFileLengths() As Label = {lblFileLength, lblFileLength1, lblFileLength2, lblFileLength3, lblFileLength4}
            For i As Integer = 0 To lblFileLengths.Length - 1
                If lblFileLengths(i).Text = "0" Then
                    bLinks(i).Visible = False
                End If
            Next
        End If

Open in new window


and get the  Error: Object reference not set to an instance of an object at
  --If lblFileLengths(i).Text = "0" Then

can someone assist?
0
Comment
Question by:JessyRobinson1234
2 Comments
 
LVL 14

Accepted Solution

by:
binaryevo earned 500 total points
ID: 37812369
Your code appears correct.  I wrote an example and was able to step through and confirm it working correctly.  Something is coming back as null in your labels it looks like.  Are you sure the labels have the correct properties set?  

Dim lbl1 As New Label()
        lbl1.Text = "0"
        Dim lbl2 As New Label()
        lbl2.Text = "1"
        Dim lbl3 As New Label()
        lbl3.Text = "2"

        Dim testFileLengths() As Label = {lbl1, lbl2, lbl3}
        For i As Integer = 0 To testFileLengths.Length - 1
            If testFileLengths(i).Text = "0" Then

                Dim s As String = "Im here"

            End If
        Next

Open in new window

0
 
LVL 21

Expert Comment

by:mastoo
ID: 37813248
Can you look at the values in the debugger when the error occurs?
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question