索引1超出范围时出错
下面的代码我想发送matrix1Col和matrix2Col乘法。索引1超出范围时出错
但它与索引1超出边界的错误。
从
double kk[2][2] = {{1,2},{5,6}};
double t [2][1] = {1,2};`
if (!matrix1Col) {
matrix1Col = [NSMutableArray array];
}
for (unsigned int i=0; i<2; i++) {
matrix1Row = [NSMutableArray new];
for (unsigned int j=0 ; j<2; j++) {
[matrix1Row addObject:@(kk[i][j])];
}
[matrix1Col addObject:matrix1Row];
}
if (!matrix2Col) {
matrix2Col = [NSMutableArray array];
}
for (unsigned int i=0; i<2; i++) {
matrix2Row = [NSMutableArray new];
for (unsigned int j=0; j<1; j++) {
[matrix2Row addObject:@(t[i][j])];
}
[matrix2Col addObject:matrix2Row];
}
NSMutableArray *resultMultiply = [self multiply:matrix1Col :matrix2Col];
在ViewController.m另一种方法里面的UIButton代码:
这是错误代码:
2013-02-14 06:26:06.595 matrixMutableArray[21578:c07] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
我找不到它在那里的错误。
感谢您的评论。
该错误发生在该行:
double value2 = [[[matrix2 objectAtIndex:k] objectAtIndex:j] doubleValue];
当错误发生时K = 0和j = 1。 matrix2的objectAtIndex:0只有一个对象,因此是错误。
谢谢你。我已经把它改成0了。但是我想知道为什么j = 1,而我把它设置得比matrix2RowCount小,而matrix2RowCount是1; – selfsheariffter 2013-02-14 01:29:17
@selfsheariffter,不,我的调试器说matrix2RowCount是2. – rdelmar 2013-02-14 01:33:18
非常感谢你。 – selfsheariffter 2013-02-14 02:12:25
错误发生在哪里? – Sebastian 2013-02-14 00:04:15