这个问题该怎么解决呢
1 #region//向PFXJ表中插入Ln项集,并返回Ln,参数为Ln的后选项(Cn) 2 public string[,] LnInsertToPFXJ(string[,] L, int minSupport) 3 { 4 int hang = L.GetLength(0); 5 int lie = L.GetLength(1); 6 7 string[,] Cn = new string[hang, lie]; 8 int max = 0;//得到的Ln的实际行数 9 10 for (int i = 0; i < hang; i++) 11 { 12 StreamReader sr = new StreamReader("My.txt", Encoding.GetEncoding("gb2312")); 13 string line = string.Empty; 14 int zhiChiPinDu = 0; 15 int num = 0;//用来判断是否二维数组的行中元素满足条件 16 string strLn = string.Empty;//存候选项集元素 17 while ((line = sr.ReadLine()) != null) 18 { 19 for( 20 21 int j = 0; j < lie; j++) 22 { 23 if (line.Contains(L[i, j]))/*此处抛出异常,对应堆栈中的中的> HouseSale.exe!HouseSale.Apriori.LnInsertToPFXJ(string[,] L, int minSupport) 行 294 C#*/ 24 { 25 int lineLen = line.Length; 26 if (L[i, j].Length == 3 && lineLen > 3 && (line.Substring(lineLen - 4, 1) == "I")) 27 { 28 int len = line.IndexOf(L[i, j]); 29 string str = line.Substring(len + 3, 1); 30 if (str == "I") 31 { 32 num += 1; 33 } 34 } 35 else 36 { 37 num += 1; 38 } 39 } 40 } 41 if (num == lie) 42 { 43 zhiChiPinDu += 1; 44 } 45 num = 0; 46 } 47 sr.Close(); 48 if (zhiChiPinDu >= minSupport) 49 { 50 for (int j = 0; j < lie; j++) 51 { 52 strLn += (L[i, j] + ","); 53 54 } 55 strLn = strLn.Substring(0, strLn.Length - 1); 56 string sql = "insert into PFXJ values('" + lie.ToString() + "','" + strLn + "','" + zhiChiPinDu.ToString() + "')"; 57 ErpApplication erp = new ErpApplication(); 58 59 erp.Esql(sql); 60 61 62 max += 1; 63 64 string myStr = string.Empty; 65 for (int j = 0; j < lie; j++) 66 { 67 if (strLn.Contains(",")) 68 { 69 int dLen = strLn.IndexOf(","); 70 myStr = strLn.Substring(0, dLen); 71 72 Cn[max - 1, j] = myStr; 73 strLn = strLn.Substring(dLen + 1, strLn.Length - dLen - 1); 74 } 75 else 76 { 77 Cn[max - 1, j] = strLn; 78 } 79 } 80 } 81 82 strLn = string.Empty; 83 }
调用堆栈如下:
[外部代码]
> HouseSale.exe!HouseSale.Apriori.LnInsertToPFXJ(string[,] L, int minSupport) 行 294 C#
HouseSale.exe!HouseSale.Apriori.MyApriori(string[] Id, int minSupport) 行 169 C#
HouseSale.exe!HouseSale.DigDataForm.button5_Click(object sender, System.EventArgs e) 行 97 C#
[外部代码]
HouseSale.exe!HouseSale.ChooseForm.button5_Click(object sender, System.EventArgs e) 行 205 C#
[外部代码]
HouseSale.exe!HouseSale.Program.Main() 行 21 C#
[外部代码]
1.string[,] L是否为null
2.L[i,j]是否为null
调试的时候,L[i,j]确实是空的。
名称 值 类型
L {string[10, 2]} string[,]
L[i, j] null string
i 3 int
j 1 int
lie 2 int
line "I11I31" string
this {HouseSale.Apriori} HouseSale.Apriori
我这是实现Apriori算法,总感觉意思不好表述出来。大致意思就是,要选择几个项进行挖掘,总共有7个项。其实一开始选择3-4个的时候,可以正常进行。但是,试图添加一个的时候,就出问题了。在这之前有4个项进行挖掘。然后我加了一个,也就是5个的时候,就出了这问题。
1.string[,] L是否为null
2.L[i,j]是否为null