2012-04-24 29 views
-2

我使用的線程文件和進程的內容閱讀。我有以下代碼:我該如何解決這個「不設置到對象的實例對象引用,使用新的」錯誤

Dim line As String = Nothing 
Dim result As String = Nothing 
Dim solved As Boolean 
While strReader.EndOfStream <> True 
    SyncLock strReader 
     line = strReader.ReadLine() 
     result = "ERROR" 
    End SyncLock 
    solved = False 
    While solved = False 
     result = Process(line) 
     If Not result.Contains("ERROR") Then 
      solved = True 
     End If 
    End While 
    //some code 
End While 

,它給我的錯誤在行:如果不result.Contains(「ERROR」)然後

與標籤工作正常,但我看書上說他們是壞的編碼。

我怎樣才能擺脫這種錯誤的?我究竟做錯了什麼?

謝謝!

+1

什麼是'過程()'?顯示你的函數的代碼,它似乎返回'Nothing'。這是一堂課嗎? – 2012-04-24 22:56:21

+0

是的,你說得對,它被定義爲沒有第一 – 2012-04-24 22:58:08

+1

顯示你的過程代碼() – JohnFx 2012-04-24 22:58:42

回答

1

錯誤相當多說,這一切

Process(line) 

返回一個空值。修復Process()以返回非空值。

或者你可以這樣做

If not result is nothing then 
    solved = not result.Contains("ERROR") 
End if 
+0

謝謝,但我認爲問題出現在具有另一個while循環的進程函數中,並且每次都返回空字符串而不是循環。 – 2012-04-24 23:15:06

+0

這正是我的答案所說的。 – JohnFx 2012-04-24 23:16:32

相關問題