2016-12-06 2 views
-1

Ceci est mon codeNull Visual Basic .Contains() Exception

  Dim words(0) As String 
      Dim trie As String 
      Dim temp As String 
      For i = 1 To 26 
       trie = encrypt(a, -i) 
       Console.WriteLine(trie) 
       For j = 0 To words.Length - 1 
        temp = words(j) 
        If trie.Contains(temp) Then 
         Console.ReadLine() 
        End If 
       Next 
      Next 

Il faut vérifier si un article contient Trie les mots du tableau, mais il renvoie une exception NULL.

encrypt(a, -i) change juste des lettres dans la chaîne

+0

Manque de détails .. Qu'est-ce 'a'? –

+0

Quelle est l'exception? –

+0

['String.Contains'] (https://msdn.microsoft.com/de-de/library/dy85x1sa (v = vs.110) .aspx) lance une' ArgumentNullException' si l'argument transmis est une référence null. Donc, vous devez le vérifier: 'Si la température n'est pas Nothing etAlors trie.Contains (temp) Then ...' –

Répondre

0

Vous devez vérifier si ces variables sont: nulls

Dim words(0) As String = String.Empty 
Dim trie As String = String.Empty 
Dim temp As String = String.Empty 

For i = 1 To 26 
    trie = encrypt(a, -i) 
    Console.WriteLine(trie) 
    For j = 0 To words.Length - 1 
     temp = words(j) 
     If Not temp Is Nothing AndAlso _ 
      Not trie Is Nothing AndAlso _ 
       trie.Contains(temp) Then 
       Console.ReadLine() 
     End If 
    Next 
Next