我一直在尝试解决这个错误,我一直在使用NSArray和NSMutableDictionary。它一直给我这个错误:
错误:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex(inlove): index 1 beyond bounds [0 .. 0]'
有人可以帮助我并告诉我并知道为什么我会收到此错误吗?
CODE:
NSMutableDictionary *LicenceDictionary = [NSMutableDictionary dictionary];
NSArray *LicenceValuesArray = [[NSArray alloc] initWithArray:[fileContent componentsSeparatedByString:@"\n"]];
for (NSString *Arrayobject in LicenceValuesArray) {
if (strlen([Arrayobject UTF8String]) > 3) {
NSArray *tempArray = [Arrayobject componentsSeparatedByString(angry)" = "];
[LicenceDictionary setObject:tempArray[1] forKey:tempArray[0]];
}
}
文件内容:
CFBundleVersion = 1.100
PortalURL = value
SpineURL = value
Authactivate = value
Authvalidate = value
Authlogout = value
RoleSelection = value
RoleSelectionURL = value
CertificateIssuer = value
SpineSessionPersistance = 0
CardRemovalPersistance = 0
LockScreenAppInactive = 0
PinchZoom = 0
LoggingSupport = 0
LogoutTimer = 90
ScreenLockTimer = 60
ScreenBlankTimer = 30
ProductName = MIA
LoggingLevel = ERROR_LOG
LoggingNumber = 0
LoggingDuration = 1
UpdateType = SILENT
InjectJavaScript = 0
JavaScriptToExecute = value
CustomerLicensed = value
ExpiryMinute = 0
ExpiryHour = 0
ExpiryDay = 31
ExpiryMonth = 10
ExpiryYear = 2014
ReadOnly = 0
Audit = 1
RemoteLogURL = value
SkipCard = 0
Signature = e8ZLMxVouwGs1CSosug3NQGmq9b7TAlraPXDFQocJpw9XNmVcquFme+p5GYVUUZ7waz/33PRX1uV7ECT6z8IK/dcqie4QcVVrC1RO7OSZx71K4QGBtRSaskA2qjSqoMkVGiqDdGwyAmFP66Y8LPW49Lrh7h3tIHwNvdMovajo40=
答案 0 :(得分:2)
您需要添加保护代码,以确保您期望的条件实际上是正确的。你不能假设某些事情是真的,因为你希望它是:
NSArray *tempArray = [Arrayobject componentsSeparatedByString:@" = "];
if ([tempArray count] == 2) {
[LicenceDictionary setObject:tempArray[1] forKey:tempArray[0]];
}
另外,这个:
if (strlen([Arrayobject UTF8String]) > 3) {
应该是:
if ([Arrayobject length] > 3) {
和此:
NSArray *LicenceValuesArray = [[NSArray alloc] initWithArray:[fileContent componentsSeparatedByString:@"\n"]];
应该是:
NSArray *LicenceValuesArray = [fileContent componentsSeparatedByString:@"\n"];