我是在一個項目,在用戶之間共享播放列表的工作的一個實例,我使用的是XML文檔「playlist.xml」VB.net空引用異常:對象引用不設置到對象
以下是是給我的空引用異常
<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:未設置爲一個對象的實例對象引用。 at Service.getList(String listNick)in C:\ Users \ jamie \ Dropbox \ UNIVERSITY \ WebSite \ App_Code \ Service.vb:line 36 - line 11 on the code i posted
有人請儘快提供一些幫助,這是爲期2天到期的單元課程:/
經過root和n之後,兩者都是xml文檔的內容......但是the_list沒有任何內容,我不明白爲什麼。 –
所以,當單步執行代碼時,哪一行會拋出異常? –
當它返回時我得到異常 –