Hi,
I'm getting the following error: NullReferenceExceptionWasUnhandled on if (messageUserList[i].Contains("_0"))
.
I can't seem to find where the data is null. I've tried debugging using breakpoint yet no luck.
Basically what I intend to do is get the text from a particular textbox txtSendMsg
and write it to messageList
at position messageListPos
. Then the textbox will be cleared. The current position messageListPos
and current user currUser
(which in this case is 0) will be writen to another array messageUserList
at position messageListPos
. So far the program identifies taht the value at messageUserList[messageListPos]
is '0_0', (this I figured out from debugging). Later on the program will loop through the messageUserList
until the length of messageList
has been reached. If messageUserList
at position i contains '_0' the program should apply the following effects and so on.
lbxChatHist
is actually a TextBlock not a ListBox.
PS: I'm using WPF
string[] messageList = new string[System.Int16.MaxValue];
string[] messageUserList = new string[System.Int16.MaxValue];
byte[] userId = new byte[15];
byte currUser = 0;
int messageListPos = 0;
private void btnSendMsg_Click(object sender, RoutedEventArgs e)
{
messageList[messageListPos] = txtSendMsg.Text;
txtSendMsg.Clear();
messageUserList[messageListPos] = messageListPos.ToString() + "_" + currUser.ToString();
for (int i = 0; i < messageList.Length; i ++)
{
if (messageUserList[i].Contains("_0"))
{
lbxChatHist.FontFamily = new FontFamily("Century Gothic");
lbxChatHist.Foreground = Brushes.DeepSkyBlue;
lbxChatHist.FontWeight = FontWeights.DemiBold;
lbxChatHist.FontStyle = FontStyles.Normal;
lbxChatHist.Text += messageList[i];
}
lbxChatHist.Text += Environment.NewLine;
}
messageListPos++;
}
Thanks,
Isaac Hili