Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-04-05
2
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
binaryevo earned 1500 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

719 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