我一直在尝试使用此代码,但我得到了,对象引用未设置为标记箭头的对象实例。谁能看看我做错了什么?我只发布了相关代码。
谢谢!
错误在 // 我的错误在这里
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
namespace pkb
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : Window
{
string[] kbsubject = new string[4000];
string[] kbbody = new string[4000];
string[] wordsplit = new string[4000];
int[] hits = new int[4000];
StreamWriter WriteBody = new StreamWriter("kbsubjecttest.txt");
StreamReader readSubject = new StreamReader("kbsubject.txt");
StreamReader readBody = new StreamReader("kbbody.txt");
int IndexHolder = 0, counter = 0, counterSearch = 0, WordsIndex = 0, counterWord=0, ArrayIndex = 0;
string compareBody, compareSubject;
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
wordsplit = SearchBox.Text.Split(' ');
WordsIndex = 0;
counterWord = 0;
ArrayIndex = 0;
counterSearch = 0;
diagWindow.Items.Add(" counter = " + counter);
while (counter > counterSearch)
{ // MY ERROR BELOW
if (kbbody[counterWord].Contains(wordsplit[ArrayIndex])) // MY ERROR HERE
{
hits[ArrayIndex] = counterWord;
diagWindow.Items.Add(hits[ArrayIndex] + " " + kbbody[ArrayIndex]);
ArrayIndex++;
}
counterWord++;
WordsIndex++;
counterSearch++;
diagWindow.Items.Add(" we are on index " + counterSearch);
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
compareBody = readBody.ReadLine();
compareSubject = readSubject.ReadLine();
if (compareBody == compareSubject)
{
diagWindow.Items.Add(" Subject and Body Database compared successfully.");
IndexHolder = int.Parse(compareBody);
diagWindow.Items.Add(IndexHolder + " Index saved to variable.");
}
else
{
diagWindow.Items.Add("Error with comparison");
diagWindow.Items.Add("------------------------------");
diagWindow.Items.Add("Body comparison has " + compareBody + " where Subject comparison has " + compareSubject);
}
//load information into arrays
while (counter <= IndexHolder)
{
kbbody[counter] = readBody.ReadLine();
kbsubject[counter] = readSubject.ReadLine();
counter++;
}
diagWindow.Items.Add(counter + " Items successfully added into searchable database");
diagWindow.Items.Add(" counter = " + counter);
}
}
}