问题标签 [nsrangeexception]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ios - App crashes with 'NSRangeException' when library is empty
I am using this code to get the latest photo from the cameraRoll:
As it is, if the library cameraRoll is empty, the app will crash with this error:
I understand that my indexSet is higher than the numberOfAssets due to this:
At this point my question is "where do I put a condition that allow me to check if the assets is zero?"
If cameraRoll has more than zero, I will let the code continue, but if the count is zero, I would like to handle the issue this way as oppose to let it crash:
Thanks for your help!
ios - 尝试运行我的应用程序时,我收到“由于未捕获的异常 'NSRangeException' 而终止”消息
主程序
调试器说错误在“NSStringFromClass”行。我不知道这是什么意思或是什么,请帮助我!:/
ios - 修改 NSFetchRequest 为空数组生成 NSRangeException 索引 0 超出范围
在我最新的 iOS 应用更新中,我发现与数据库相关的崩溃显着增加。我看到几乎每一行在数据库上运行提取的代码都会崩溃。
例外:
NSRangeException
* -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
堆栈跟踪:
CoreFoundation 0x32c982a3 __exceptionPreprocess + 163
1
libobjc.A.dylib 0x3a93d97f objc_exception_throw + 31
2
CoreFoundation 0x32be3b75 -[__NSArrayM objectAtIndex:] + 165
3
CoreData 0x32a4227f -[NSSQLCore _newRowsForFetchPlan:selectedBy:withArgument:] + 2007
4
CoreData 0x32a3b089 -[NSSQLCore newRowsForFetchPlan:] + 313
5
CoreData 0x32a3a73f -[NSSQLCore objectsForFetchRequest:inContext:] + 683
6
CoreData 0x32a3a205 -[NSSQLCore executeRequest:withContext:error:] + 469
7
CoreData 0x32a3961d -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1645
8
CoreData 0x32a37f17 -[NSManagedObjectContext executeFetchRequest:error:] + 647
9
MyApp 0x000516b7 +[DBQuery searchObjectsWithEntityName:::::] + 211
10
MyApp 0x000515a1 +[DBQuery syncData] + 113
11
MyApp 0x0006a7f7 __14+[MyAppSync sync]_block_invoke + 39
12
libdispatch.dylib 0x3ad5511f _dispatch_call_block_and_release + 11
13
libdispatch.dylib 0x3ad63259 _dispatch_root_queue_drain + 261
14
libdispatch.dylib 0x3ad633b9 _dispatch_worker_thread2 + 85
15
libsystem_c.dylib 0x3ad89a11 _pthread_wqthread + 361
16
libsystem_c.dylib 0x3ad898a4 start_wqthread + 8
看起来罪魁祸首的代码行可能与添加我的 NSFetchRequest 的两行修改有关:
+ (NSFetchRequest*) getFetchRequestForEntityName:(NSString*)entityName :(NSPredicate*)predicate :(NSString*)sortKey :(BOOL)sortAscending :(int)limit :(NSManagedObjectContext*)managedObjectContext
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
//* NEW IN LATEST RELEASE **//
//**************//
}
objective-c - 范围崩溃的子字符串
我有奇怪的问题。以下子字符串代码崩溃
我假设范围在边界内,但它仍然崩溃。知道为什么会这样吗?以下是它显示的错误。
* Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFConstantString substringWithRange:]: Range or index out of bounds' * First throw call stack: (0x1c92012 0x10cfe7e 0x1c91deb 0x1c6aaa4 0x2bbc 0xf51c7 0xf5232 0x443d5 0x4476f 0x44905 0x4d917 0x27c5 0x11157 0x11747 0x1294b 0x23cb5 0x24beb 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1217a 0x13ffc 0x24fd 0x2425)抛出异常(将终止调用)
objective-c - Obj-C/Cocoa How to check if [string characterAtIndex:i] is returning an NSRangeException?
I have a for loop.
I understand from the documentation that characterAtIndex: will usually return a value of the type 'unichar' but if our index is out of bounds an NSRangeException is returned.
Being cautious, I'd like to check whether [string characterAtIndex:i] is returning an NSRangeException or not before assigning to return value to currentCharacter.
The first thing I tried was this:
...but it doesn't work because, from my understanding, the method usually returns an int and I'm comparing it to NSRangeException, which is a string.
I thought about [string characterAtIndex:i] isKindOfClass:...] but that won't work because [string characterAtIndex:i] is not an NSObject. So, uh, how do I test for the exception?
Should I be testing for the exception? How do I test for the type of the returned value if it's sometimes a primitive and sometimes an NSObject?
objective-c - 将对象添加到 NSMutableArray 时出现 NSRangeException
我正在编写 iOS 应用程序中的搜索栏逻辑。我有 1 个 NSArray “results”,其中包含从 NSFetchRequest 返回的实体,以及一个空的 NSMutableArray “resultados”,我想在其中添加从第一个数组返回的对象。
这是代码:
每次执行此行时:
我得到以下异常:
我不明白如何使用 addObjectsFromArray 方法超越任何数组边界。事实上,如果我将这条指令替换为以下基本上相同的调试代码,我可以看到我正在添加所有对象,但在添加最后一个对象时总是抛出异常,无论结果返回多少对象:
我尝试了很多变化,但我不知道发生了什么。
在此先感谢您的帮助。
objective-c - -[NSMutableArray removeAllObjects] 和 -[NSMutableArray addObject:] 抛出 NSRangeException
第一次崩溃是由调用 removeAllObjects 引起的,第二次是 addObject:
和
iphone - NSRangeException 即使范围在 NSString 替换中是正确的
我写了一个代码来替换删除NSString中的子字符串......我的逻辑是使用'rangeofString'来查找每个子字符串字符的位置,然后使用'ReplaceOccurance'用空格替换子字符串字符,然后修剪空白字符. 但是在 replaceOccurance 行中出现错误
这是我的代码。
实际上我解决了范围的问题..因为重写代码我误认为 seocond 参数不是上限而是长度..应该如下
uilabel - NSRangeException 越界错误
我正在设置标签的属性文本,我收到了这个奇怪的错误:由于未捕获的异常“NSRangeException”而终止应用程序,原因:“NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds”。我以前从未见过这个错误,所以我不知道如何解决它。这是导致崩溃的代码:
我设置了一个异常断点,它在线上崩溃了[attributedString setAttributes:attrs range:nameRange];
有谁知道我该如何解决这个问题?