Question yet another null refrenced exception!

Arash88

Member
Joined
May 20, 2014
Messages
9
Programming Experience
3-5
I know its been asked numerous of times about threading and null.reference.exception and what not and i have read every each of solutions provided, but i still couldn't figuring it out some of those nasty exceptions. i just started coding in .net and i have no clue whats wrong with my code. as far as i can tell i left nothing nulled behind. I got several exceptions in my app but these 2 points are where i couldn't fix'em :
one here:
VB.NET:
Private Sub OnIncomingMessage(ByVal Args As UNOLibs.Net.ServerClass.InMessEvArgs) Handles Srv.IncomingMessage


        If Me.InvokeRequired Then   '//i fixed the thread instance thing warning but not nullrefrence one


            Dim d As New SetTextCallback(AddressOf OnIncomingMessage)


            Me.Invoke(d, New Object() {Args})


            return


         End If


            Dim sip As String = Args.senderIP
            Dim DATA As String = Args.message


            ''/////////////////////////////////////////


            lb1.Items.Add(sip & "-->" & Data)     <=== THIS LINE
            usr_ip.Text = sip


            Parser(Data)


  End Sub


And one here:

VB.NET:
        Dim strng As String = str
        Dim p As New StringParser(strng)


        b = "|"


        Try


            Do While p.skipToStartOfNoCase(b)


                If p.skipToEndOfNoCase(b) AndAlso p.extractUntilNoCase(b, strExtract) Then


                    a.Add(strExtract)


                End If
            Loop


            Get_Inst(a, a(1))
            SetItems(a(1))


        Catch ex As Exception


            ''/// if i don't disable this line i get the msgbox even when errors occur in the previous "THIS LINE" mark or next one.


            MsgBox(ex.Message, MsgBoxStyle.Critical, "Bad input string in Parser")


        End Try


    End Sub


Private Sub Get_Inst(ByVal Ent As ArrayList, ByVal Indx As Integer)


        Select Case Ent(0)


            Case "S"


                Select Case Indx


                    Case 0, 1, 2, 3, 4, 6, 7, 8, 9


                        For i = 2 To Ent.Count - 1


                            SetItems(Indx)
                            'Me.Controls("checkbox" & i).Visible = Ent(i)
                            Dim cb As CheckBox = DirectCast(Me.Controls("CheckBox" & i), CheckBox)
                            cb.Checked = Ent(i)     <==== THIS LINE


                        Next


                End Select




            Case "I"


        End Select


    End Sub

as i mentioned in the codes, the errors happens where there is no explanation for me, i checked and as far as i can tell i left nothing nulled behind, but... sorry im a very very ****ty coder, all that matters to me is my code to run! so if u guys have any recommendation / optimization, you are very very welcomed my friends! :D:triumphant:
thanx again
 
If there's a NullReferenceException then there's a null reference, i.e. on the line that throws the exception, you are trying to access a member of an object that doesn't exist, i.e. is Nothing. What is Nothing on the line that throws the exception? You also need to look at the stack trace of the exception to check whether it's actually in your code or some code called by yours.
 
dear jmcilhinney, tnx for your quick reply, very kind of u sir

so by the terms u said, the only thing that might be nothing is this part (purple highlighted):
Dim d As New SetTextCallback(AddressOf OnIncomingMessage)

because in this part i can see my {args} contain exactly what should it does (green highlight):
Me.Invoke(d, New Object() {Args})

this is the stacktrace i've collected at my first mark. the thing is i have no idea what does it mean or where should i begin to look first.
can u help me through it plz?i'm very confused, cuz i'm using a component named UNOLIBS.Net for my Socket part and i've done everything the instruction said,
it's simple and easy but...:blue:

at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at WMSInterface.Form1.OnIncomingMessage(InMessEvArgs Args) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WMSInterface\WMSInterface\Form1.vb:line 755
at UNOLibs.Net.ServerClass.OnConnectTS()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
 
Last edited by a moderator:
I said this:
What is Nothing on the line that throws the exception?
You said that this is the line that throws the exception:
VB.NET:
lb1.Items.Add(sip & "-->" & Data)
That suggests to me that the most likely answer is that 'lb1' is Nothing when the exception is thrown. Have you checked?
 
hi jmcilhinney, tnx for your help

actually add the point that i mentioned i have a cross-thread exception and after i add this code i get nullreferenced excep at the below mark and the stacktrace is as same as above :ambivalence:

VB.NET:
If Me.InvokeRequired Then   '//i fixed the thread instance thing warning but not nullrefrence one


            Dim d As New SetTextCallback(AddressOf OnIncomingMessage)


            Me.Invoke(d, New Object() {Args})  <=== THIS POINT , Args already contains the correct values


            return


 End If

tnx in advance :blue:
 
Last edited:
I asked a question and you haven't provided an answer. If you don't provide the information requested when requested then you're not going to get the help you want.
 
hi jmcilhinney, tnx for your reply:couple_inlove:
actually i'm not sure if it does, all i did was to select a listbox, drag it on the form, change its name and finally use it where i marked , im not sure if i should initialize it somewhere else. about the other objects like unolibs methods or other controls i have the same question, should i initialize every thing i wanna use and if the answer is positive then how should i do it?:rofl:
i really appreciate your efforts to helping me out, tnx again bro
 
Back
Top