问题标签 [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.

0 投票
1 回答
204 浏览

ios8 - 我无法在真实设备上的 IOS8 应用程序中仅显示简单的 UIActionSheet

当我在 IOS 8 中运行它时,我得到 NSRangeException 异常

输出异常:

2014-09-26 22:18:17.106 rcherzios[354:51170] * 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[__NSArrayM replaceObjectAtIndex:withObject:]:索引 0 超出空数组的范围” *首先throw call stack: (0x2b153f87 0x38bc6c77 0x2b071331 0x10b587 0x2b96109b 0x2b961211 0x2b965897 0x2b963141 0x2b963579 0x2b964391 0x2b964215 0x2b966e2d 0x2b9641ab 0x2b99e65b 0x2b99d067 0x2b99ca87 0x2b9643e7 0x2b964215 0x2b966e2d 0x2b9641ab 0x2b99bd01 0x2b966e2d 0x2b99bc79 0x2b953bed 0x2b953ceb 0x2b11a82d 0x2b119af1 0x2b11864b 0x2b065db1 0x2b0af6cb 0x2b966b7f 0x392a6e67 0x392a6ddb 0x392a4b84) libc++abi.dylib: terminating with uncaught NSException 类型的异常信号:6(信号 SIGABRT)

在 IOS7 甚至在模拟器 IOS 8 中一切正常,只是在 IOS8 的真实设备上它崩溃了......

看起来在我工作了 3 年的复杂应用程序中,所有 UIAlertView 都因相同的异常而崩溃,我试图测试新的 UIAlertController 并有相同的异常。所以我的结论是我的应用程序的某些配置导致 UIAlertController 出现问题,实际上 UIAlertView 和 UIActionSheet 在 ios 8 中使用的是什么。

0 投票
1 回答
576 浏览

ios - 在 Objective C/XCode 6 中检查用户输入的 URL - NSRangeException

天,

我正在尝试在浏览器应用程序中检查用户输入的 URL。目的是在用户没有输入 http:// 等方案时添加它,并且如果他们在文本字段中包含任何空格,则假定他们在谷歌搜索之后。

我想我就快到了,但是每当我输入不是完整的 URL 并且没有空格的内容时,就会由于以下错误而崩溃。简单地说,

  • 输入“National Rugby League”将使用该搜索词正确加载 Google
  • 输入“ http://www.nrl.com.au ”正确加载 NRL 网页
  • 输入“www.nrl.com.au”会导致以下错误:

由于未捕获的异常“NSRangeException”而终止应用程序,原因:“-[__NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds”

我查看了以下类似的问题,但没有运气:

如何验证 iPhone 上的(原文如此)网址

检查字符串是否是 url 目标 c

NSRange 崩溃的应用程序

这个问题与我的非常相似,但没有完全回答:

更正用户在 xcode 目标 c 中提交的 url

请在下面找到我的代码

}

感谢您提供的任何帮助,非常感谢!

0 投票
1 回答
488 浏览

ios - NSRangeException,但在哪里?

我有一个应用程序,用户报告它在随机时间崩溃。所有崩溃都有相同的堆栈

这可能看起来不错,但是当我查看级别 3、8 和 9 时,代码不再有意义。

错误是 NSRangeException

谁能告诉我这里发生了什么?

0 投票
6 回答
13133 浏览

ios - [__NSArrayM objectAtIndex:]:索引 2 超出范围 [0 .. 1]

我是一名新的 iOS 开发者;我有一个带有解析和动态单元格的应用程序,但是当我运行该应用程序时,我发现该应用程序由于标题上的原因而崩溃,我的代码如下

我将第一个屏幕 UICollectionView 用于解析为以下代码的动态数据

pragma collectionView 委托

我需要一些帮助才能知道错误在哪里;每次我在控制台上收到此错误[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]

0 投票
1 回答
190 浏览

ios - Uncaught exception - NSRangeException

I've been trying to sort out this error I keep getting with NSArray and NSMutableDictionary. It keeps giving me this error:

ERROR:

Could someone please help me and give me and idea why i'm getting this error?

CODE:

FILE CONTENT:

0 投票
1 回答
583 浏览

objective-c - NSRangeException 索引 1 超出范围 [0 .. 0] 用于非空数组

背景:我目前正在为 iTunes U 上斯坦福大学最新的 cs193p 课程做作业 2。我试图避免简单地查找解决方案,但我被困住了。

问题:对于以下代码:

我不断得到以下结果:

为什么 ): ?显然,我的数组在索引 0 处包含一个对象,并且显然数组的边界超出了 [0 .. 0]。

0 投票
4 回答
1415 浏览

ios - 混合静态和动态 UITableViewController 内容会导致 NSRangeException

我一直在寻找这个错误,并确实找到了一些具有类似行为但没有解决问题的解决方案的帖子。

我有一个 UITableViewController(在 SB 中声明为静态),它必须有部分:第 0 部分(配方)是静态的,有 4 个单元格,第 1 部分(风味)应该是动态的

故事板截图

这是我用来测试的代码:

现在我在运行时遇到的错误是:'NSRangeException',原因:'*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

我知道我在某个地方错过了一些小东西,有人可以帮助我吗?

非常感谢

0 投票
1 回答
185 浏览

ios - 本地化应用程序因 NSRangeException 而崩溃

我有一个 iOS 应用程序,它在两种语言中运行良好——我知道添加了一些东西,已经记住使用 NSLocalizedString 进行本地化等。该应用程序的英文版本到目前为止运行良好,但第二语言版本在之后立即崩溃开始。为什么?

应该注意的是,我没有在我的 localizable.strings 文件中添加所有 NSLocalizedStrings。此外,我有两个独立的故事板,用于英语和德语。任何帮助将不胜感激!

编辑

0 投票
0 回答
218 浏览

ios - cancelAuthenticationChallenge fails with NSRangeException after user hits No

I am trying to cancel an NSURLAuthenticationChanllenge if the server certificate cannot be validated (in my case a self-signed), by popping up an UIAlertView with two buttons -- 'No' and 'Yes'

when user hits Yes, I proceed anyway, but when user hits No, I cancel it. This is how i am doing it. I am using the delegate for the UIAlertView to capture the index of the button that was clicked by the user. When I click Yes, it works fine, but when you click on No, I get an NSRangeException

}

Here is the delegate

}

The error is: * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

As requested-- here is the full stackTrace

i tried to add the image of the stack trace -- but the image is too small. here is the text. please copy into textEdit-- it should be better

[NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]' *** First throw call stack: ( 0 CoreFoundation 0x004e5946 __exceptionPreprocess + 182 1 libobjc.A.dylib 0x02bd2a97 objc_exception_throw + 44 2 CoreFoundation 0x003c8bd2 -[__NSArrayI objectAtIndex:] + 210 3 MYCODE** 0x0017d9e1 -[HttpUtils getAuthTokenExpiration:] + 145 4 MYCODE** 0x0017dfb3 -[HttpUtils saveAuthTokenExpirationDate:] + 99 5 MYCODE** 0x0017ed5a __68-[HttpUtils getToken:params:username:password:tokenCompletionBlock:]_block_invoke + 218 6 MYCODE** 0x001850ce -[HttpUtils connection:didFailWithError:] + 334 7 CFNetwork 0x0497d38e __67-[NSURLConnectionInternalConnection cancelAuthenticationChallenge:]_block_invoke + 51 8 CFNetwork 0x04995879 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 83 9 CFNetwork 0x0497cdd9 -[NSURLConnectionInternalConnection invokeForDelegate:] + 145 10 CFNetwork 0x04995813 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 189 11 CFNetwork 0x04995a10 -[NSURLConnectionInternal _withConnectionAndDelegate:] + 58 12 CFNetwork 0x0497d314 -[NSURLConnectionInternalConnection cancelAuthenticationChallenge:] + 384 13 CFNetwork 0x048c100d -[NSURLConnection(NSURLAuthenticationChallengeSender) cancelAuthenticationChallenge:] + 50 14 MYCODE** 0x00184b82 __58-[HttpUtils connection:didReceiveAuthenticationChallenge:]_block_invoke + 370 15 MYCODE** 0x00184f52 -[HttpUtils alertView:clickedButtonAtIndex:] + 178 16 UIKit 0x0186960d -[UIAlertView _prepareToDismissForTappedIndex:] + 192 17 UIKit 0x01868fa9 __35-[UIAlertView _prepareAlertActions]_block_invoke50 + 56 18 UIKit 0x018618b5 -[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:] + 72 19 UIKit 0x01861868 -[UIAlertController _dismissAnimated:triggeringAction:] + 56 20 UIKit 0x01861454 -[UIAlertController _actionViewTapped:] + 68 21 libobjc.A.dylib 0x02be8771 -[NSObject performSelector:withObject:] + 70 22 UIKit 0x01a4474c -[_UIAlertControllerActionView _triggerSelect] + 60 23 UIKit 0x01a44607 -[_UIAlertControllerActionView touchesEnded:withEvent:] + 187 24 UIKit 0x019e47b7 _UIGestureRecognizerUpdate + 13225 25 UIKit 0x015fb26b -[UIWindow _sendGesturesForEvent:] + 1356 26 UIKit 0x015fc0cf -[UIWindow sendEvent:] + 769 27 UIKit 0x015c1549 -[UIApplication sendEvent:] + 242 28 UIKit 0x015d137e _UIApplicationHandleEventFromQueueEvent + 20690 29 UIKit 0x015a5b19 _UIApplicationHandleEventQueue + 2206 30 CoreFoundation 0x004091df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15 31 CoreFoundation 0x003feced __CFRunLoopDoSources0 + 253 32 CoreFoundation 0x003fe248 __CFRunLoopRun + 952 33 CoreFoundation 0x003fdbcb CFRunLoopRunSpecific + 443 34 CoreFoundation 0x003fd9fb CFRunLoopRunInMode + 123 35 GraphicsServices 0x0697324f GSEventRunModal + 192 36 GraphicsServices 0x0697308c GSEventRun + 104 37 UIKit 0x015a98b6 UIApplicationMain + 1526 38 MYCODE** 0x001f857d main + 141 39 libdyld.dylib 0x03349ac9 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

** removed my app name and replaced with string MYCODE

0 投票
2 回答
278 浏览

objective-c - 删除 UICollectionView 单元格时出现 NSRangeException

我试图从循环中删除单元格UICollectionViewfor.. in每次我得到NSRangeException. 我不明白为什么会发生这种情况,因为首先我对数组进行排序然后尝试删除。所以问题是我首先尝试向服务器发送请求,并且只有当响应成功时,我的UICollectionView单元格和数组元素才会被删除。这是我的代码:

通过循环传递元素:

例如,在这里我选择了 6 个单元格,并且我的数组按照从上到下的正确顺序(5、4、3、2、1、0)排序。然后我按照这个顺序在方法中传递这些元素。

请求发送方法:

所以在上面的方法中,我在两个或三个元素已经通过后得到错误的元素编号,即第一个元素是5,然后是 4,然后2、3、1、0 。此时我处理异常并尝试删除元素,然后我得到我的应用程序崩溃。我做错了什么?@catch[smArray removeObjectAtIndex:(unsigned int)pathRow-1];NSRangeException