Solved

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

Posted on 2012-04-05
2
180 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML & .net 5 40
VB.net/WinForms: adjust Screen Resolution 6 40
Server Error 11 47
Vb. Net application freezes 9 30
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now