Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Guys,

I'm creating a WPF page which to show current map location of the device at default page. What I'm weird is, my application log has captured a variable passed to the function is NOTHING where before it go into the function, the variable "devloc" with be hold a value from configuration settings let's say GF or LG from udt.devfloor.

It appear when I'm breakpoint to the udt.devfloor, it will skip it value to devloc and jump to the exception directly. If I continue run after it breakpoint, it will like cycle loop the instance back and the cycle is ok.

The exception:-
VB
{"Object reference not set to an instance of an object."}


Find my flow below:-
VB
Public Sub New()
        MyBase.New()
        Me.InitializeComponent()
        devloc= udt_config.devfloor
        ViewSelectedDeviceLoc(devloc, 100)
End Sub
Private Sub ViewSelectedDeviceLoc(ByVal floor As String, ByVal width As Integer)
    Try
        If floor.Contains("C/") Then '// this is where the floor become nothing
            img_maps.Source = obj_core.ReturnSpecificImage(mymapspath & "B1.png", width)
        Else
            img_maps.Source = obj_core.ReturnSpecificImage(mymapspath & floor & ".png", width)
        End If
        img_maps.Stretch = Stretch.Uniform
        img_maps.StretchDirection = StretchDirection.Both
    Catch ex As Exception
        strMsg = "[" & strlogpage & "] Error at view " & floor & " map 2. Ex:" & ex.Message '//exception direct here
        App.LogEvents(strMsg, EventLogEntryType.Error)
    End Try
End Sub


What I have tried:

Trying to reinitialize the variable if it nothing:-

If IsNothing(udt_config.devfloor) Then
devloc= udt_config.devfloor
End If

It still same. It just happen at the very first time when application is started and the page is load for the very first time. It will not having
Posted
Updated 24-Jun-16 7:19am
v2

1 solution

Keep going backwards in the code. Where did the valuve of "floor" come from? It had to be passed in from some other method that called ViewSelectedDevice. This is where looking at the Stack Trace comes in handy.

I'm assuming that it came from your constructor when you "New"d up a new instance of this class. In the constructor, you have this:
VB
Public Sub New()
        MyBase.New()
        Me.InitializeComponent()
        devloc= udt_config.kiosklevel
        ViewSelectedDeviceLoc(devloc, 100)
End Sub

So, why is "devloc" Nothing when it makes the call to ViewSelectedDeviceLoc? What does the udt_config.kiosklevel code do that makes it return Nothing?
 
Share this answer
 
Comments
Luiey Ichigo 24-Jun-16 13:22pm    
Dave,

That is what I'm curious about. The function will be use on the same page but on different button so each button will assign value of it to the parameters. There will be a LG, GF, L1, L2 button. I try to move the code to private sub. But same exception occur when running the program and go to the map page.
Dave Kreskowiak 24-Jun-16 13:54pm    
I've told you how to find the problem. Follow the stack trace back to the caller, set breakpoints as appropriate and inspect the values of the vriables involved. You have to trace this Nothing value back to its source to find out why it's Nothing and the not the value to expect.

We can't do that for you.
Luiey Ichigo 24-Jun-16 14:20pm    
Ok dave, I understand. Now I want to share my finding. I put a breakpoint on devloc= udt_config.kiosklevel and yes it will pass the value and I step into every line of code. Yes the floor with have value.

But if I delete the breakpoint which it will running normally, ahaa devloc will be nothing.

Stepping through each line start from assigning value to the devloc on breakpoint, all is well. Retract back breakpoint, nothing.

I just want to know how this problem is called in programming side. I search for "wpf value is nothing when first time load" and it just an article of some VS. Might wrong on my keywords
Dave Kreskowiak 24-Jun-16 15:28pm    
and you will never find anything like what you're describing.

What is udt_config.kiosklevel and the code behind it?
Luiey Ichigo 25-Jun-16 13:12pm    
udt_config.kiosklevel is a string structure when first Application_Startup that retrieve program setting from App.Config file..

This was my structure declare in global module:-

<pre lang="VB.NET">
Public udt_config As CONFIG

Public Structure CONFIG
Dim kioskid As String
Dim kioskloc As String
Dim kiosklevel As String
End Structure</pre>

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