1
I’m having trouble with this code.
Whenever it rotates, it causes an exception of the type System.NullReferenceException
.
// Clear out the Array of code words
wordBuffer = null;
Int32 syntaxCount = 0;
// Create the regular expression object to match against the string
Regex defaultRegex = new Regex(@"\w+|[^A-Za-z0-9_ \f\t\v]",
RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match wordMatch;
// Loop through the string and continue to record
// words and symbols and their corresponding positions and lengths
for (wordMatch = defaultRegex.Match(s); wordMatch.Success; wordMatch = wordMatch.NextMatch())
{
var word = new Object[3] { wordMatch.Value, wordMatch.Index, wordMatch.Length };
wordBuffer[syntaxCount] = word;
Debug.WriteLine("Found = " + word[0]);
syntaxCount++;
}
// return the number of symbols and words
return syntaxCount;
The exception occurs in these two lines (if I remove the first, the exception occurs in the second):
Debug.WriteLine("Found = " + word[0]);
syntaxCount++;
Specifically when I try to take the value of word[0]
, And on the second line with the variable syntaxCount
, but none of them has the null value, as you can see in the image below:
The variable "s" is just a row of a Richeditbox, word[0]
has a value, so why is causing the exception NullReferenceException
? syntaxCount
has a value too :/
http://answall.com/help/mcve
– Maniero