我又回来了,我在这里找不到解决办法。有人可以帮我一把吗?我遇到了“将对象引用设置为对象实例”的问题。
PS:我在这里读到了一些与这个问题相关的链接,但仍然没有运气。这是链接“What is a NullReferenceException, and how do I fix it?”它说,我们必须检查并填充变量以确保变量具有值。但在我的情况下,我的变量有一个值,为什么它返回“NullReference”错误?
谢谢大家。
以下是我的代码。 (不是整个模块只是程序)
Private m_imp As Object ' We delegate the details of horz or vert to this class
Public Sub addWidget1(ByRef widget As Object, ByRef minExtent As Object)
m_widget1 = widget
'UPGRADE_WARNING: Couldn't resolve default property of object widget.ZOrder. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
widget.ZOrder()
'UPGRADE_WARNING: Couldn't resolve default property of object m_imp.minExtent1. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object minExtent. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
m_imp.minExtent1 = minExtent ' <---- HERE IS THE ERROR
End Sub
错误:发生了System.NullReferenceException
PS:代码调用功能的错误。
Private Sub initGUI(ByRef splitter As clsSplitLayout, ByRef navpane As clsPaneNav, ByRef contentpane As clsPaneContent, ByRef detailpane As clsPaneDetail)
Dim hsplit As New clsSplitLayout
With hsplit
.SplitType = clsSplitLayout.SplitterType.HORIZONTAL_SPLIT
.createSplitBar("bar1", Me)
.addWidget1(contentpane, 2000) '<--- HERE'S HOW I CALL THE FUNCTION THAT HAS ERROR.
.addWidget2(detailpane, 2000)
End With
答案 0 :(得分:0)
当您正在读取其中包含n值的变量时,会发生System.NullReferenceException。
在您的情况下,定义了m_imp但它没有值。
在访问m_imp之前,m_imp必须具有值。