第一次加载页面时,变量无效。为什么? [英] Variable is nothing at first time page load. Why?

查看:79
本文介绍了第一次加载页面时,变量无效。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,



我正在创建一个WPF页面,用于显示默认页面上设备的当前地图位置。我奇怪的是,我的应用程序日志捕获了一个传递给函数的变量NOTHING,在进入函数之前,变量devloc与配置设置保持一个值让我们说来自udt.devfloor的GF或LG 。



当我是udt.devfloor的断点时,它会跳过它的值到devloc并直接跳转到异常。如果我继续在断点之后运行,它将循环循环实例并且循环正常。



异常: -

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:-

{"Object reference not set to an instance of an object."}





在下面找到我的流程: -



Find my flow below:-

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





我尝试了什么:



尝试重新初始化变量,如果没有: -



如果IsNothing(udt_config.devfloor)那么

devloc = udt_config.devfloor

结束如果



它仍然相同。它恰好发生在第一次启动应用程序并且第一次加载页面时。它不会有



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

推荐答案

继续在代码中倒退。 地板的价值来自哪里?它必须从一些名为ViewSelectedDevice的方法传入。这就是查看Stack Trace的用武之地。



我假设它来自你的构造函数,当你新建这个新实例时类。在构造函数中,您有:

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:
Public Sub New()
        MyBase.New()
        Me.InitializeComponent()
        devloc= udt_config.kiosklevel
        ViewSelectedDeviceLoc(devloc, 100)
End Sub



那么,为什么devloc在调用ViewSelectedDeviceLoc时没什么? udt_config.kiosklevel 代码是什么让它返回Nothing?


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?


这篇关于第一次加载页面时,变量无效。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆