【发布时间】:2013-12-30 03:45:55
【问题描述】:
我正在开发一个在用户之间共享播放列表的项目,我正在使用 XML 文档“playlist.xml”。
以下是给我空引用异常的代码
<WebMethod()> _
Public Function getList(ByVal listNick As String) As String
Dim root As XmlNode = getDocument()
Dim number As Double
Dim n As XmlNodeList
n = root.SelectNodes("//playlist")
number = n.Count
Dim found As Boolean = False
'For Each node As XmlNode In n
Dim the_list As String = root.SelectSingleNode("playlists/playlist[@name='" + listNick + "']").InnerXml
Return the_list
'n = root.SelectSingleNode(“WebShop/Departments/Department[@name=’Hardware’])
'Next
If (Not found) Then
'Return "Not found among: " + number.ToString + "\n" + "did find: " + n.Item(1).Value ---to test for errors
Return "0"
Else
Return "[getList] if you read this, jamie has failed his logic somewhere."
End If
End Function
这是堆栈跟踪:
System.NullReferenceException:对象引用未设置为对象的实例。 在 C:\Users\jamie\Dropbox\UNIVERSITY\WebSite\App_Code\Service.vb 中的 Service.getList(String listNick):第 36 行 -- 我发布的代码的第 11 行
这是大学的课程。
【问题讨论】:
标签: vb.net xpath nullreferenceexception