Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!

I'm getting Null Reference Exception unhandled error. The error shows: "Object reference not set to an instance of an object" on the line

j=localgroupdata.Tables("GroupTable").Rows.Count()

If I set j=10, the error shows on i:
For i = 0 To (j - 1)

Please help me.

***************************************
VB
Private Sub FillListbox()
    Dim i, j As Integer
    Dim localGroup As New Group()
    localgroupdata = localGroup.GetGroups()
    localGroup = Nothing
    j = localgroupdata.Tables("GroupTable").Rows.Count()
    For i = 0 To (j - 1)
        lstGroups.Items.Add(localgroupdata.Tables(0).Rows(i)(0))
    Next
    lstGroups.SelectedIndex = 0
End Sub

**************************************

Thanks!
Posted
Updated 12-Jan-11 21:46pm
v2
Comments
Dalek Dave 13-Jan-11 3:46am    
Edited for Readability.
justinonday 13-Jan-11 5:17am    
check j's value comming??

1 solution

You didn't check the localGroup.GetGroups() return value, namely localgroupdata.
:)
 
Share this answer
 
Comments
kumarsajith01 13-Jan-11 3:43am    
when I debug, it shows nothing as value. How to solve this problem? Shall I use IF..? Could you suggest detailed correction to the code
CPallini 13-Jan-11 3:48am    
Of course you should avoid to reference a 'nothing' object. You may use a condition (like you said) or you may just handle the exeception. In any case, why is it 'nothing' (I mean are you sure you should get it on a freshly created 'Group'?)?
kumarsajith01 13-Jan-11 3:57am    
Thank you very much. I'll recode it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900