首页 \ 问答 \ iOS:无法在NSMutableDictionary中设置空值(iOS: can't set the null value in an NSMutableDictionary)

iOS:无法在NSMutableDictionary中设置空值(iOS: can't set the null value in an NSMutableDictionary)

我试图在NSMutableDictionary设置一个值,但我总是得到这个错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSDictionaryI 0x10fd55990> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key image.'

在NSMutableDictionary中,我有一个@"image"字段,可以为null 。 我想用占位符图像名称替换null值。 这是我如何做到的:

NSMutableDictionary * item = self.carouselSource[index];
if([Utils isNull:[item valueForKey:@"image"]]) {
[item setValue:@"default_image.png" forKey:@"image"]; 
}

但是应用程序在这一行中崩溃

[item setValue:@"default_image.png" forKey:@"image"];

由于上面的错误。


I'm trying to set a value in an NSMutableDictionary but I'm always getting this error:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSDictionaryI 0x10fd55990> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key image.'

In the NSMutableDictionary I have an @"image" field that can be null. I want to replace the null value with a placeholder image name. This is how I do it:

NSMutableDictionary * item = self.carouselSource[index];
if([Utils isNull:[item valueForKey:@"image"]]) {
[item setValue:@"default_image.png" forKey:@"image"]; 
}

But the application crash in this line

[item setValue:@"default_image.png" forKey:@"image"];

due to the error above.


原文:https://stackoverflow.com/questions/45633521
更新时间:2023-10-13 16:10

最满意答案

问题已经解决了! Epic Fail:为了连接到servlet以获得响应,我必须连接到另一个servlet来启动会话,而不是保存cookie并继续。 我使用HttpsURLConnection,它工作安静,很好... Fazit:流媒体在Android上运行良好


The problem is solved! Epic Fail: befor i connect to the servlet to get the response i have to connect to another servlet to start the session, than save the cookie and go on. i Used HttpsURLConnection and it works quiet good... Fazit: Streaming works well on Android

相关问答

更多
  • 那么Apache Commons IOUtils.readLines()呢? 获取InputStream的内容作为字符串列表,每行一个条目,使用平台的默认字符编码。 或者,如果您只想使用一个字符串,请使用IOUtiles.toString() 。 使用平台的默认字符编码将InputStream的内容作为字符串获取。 [更新]根据关于这个在J2ME上可用的评论,我承认我错过了这个条件,但是IOUtils的源代码在依赖性上非常轻,所以也许代码可以直接使用。 What about Apache Commons I ...
  • 使用适合的URL(包括协议!)的java.net.URL#openStream() )。 例如 InputStream input = new URL("http://www.somewebsite.com/a.txt").openStream(); // ... 也可以看看: 使用java.net.URLConnection来触发和处理HTTP请求 Use java.net.URL#openStream() with a proper URL (including the protocol!). E.g ...
  • 所以我也在nginx论坛上发帖,我收到了回复。 我特意寻找的东西称为“无缓冲上传”,这是目前nginx不提供的功能。 使用websockets是不可能的,因为后来这个原型需要在一个使用http协议的更大更旧的系统中实现。 所以答案就是“nginx”不可能。 对于面临同样问题的任何人来说,可能的工作是使用tengine,这是一个nginx分支。 So I also posted on the nginx forum and I got a reply. The thing I am specifically ...
  • 问题已经解决了! Epic Fail:为了连接到servlet以获得响应,我必须连接到另一个servlet来启动会话,而不是保存cookie并继续。 我使用HttpsURLConnection,它工作安静,很好... Fazit:流媒体在Android上运行良好 The problem is solved! Epic Fail: befor i connect to the servlet to get the response i have to connect to another servlet to ...
  • 我有树观察,首先在类Info中,Picture成员必须是一个byte []数组,你不能使用流,第二个在servlet中,当你返回一个json响应时,内容类型是response.setContentType(“application / json” “);. 第三,也是最重要的img标签中的属性src仅支持图像文件的URL,它不能接收图像的字节。 我建议你从数据库中读取图像,创建一个临时图像文件并发送要在img标签中使用的url。 在混合移动应用程序中,我使用javascript渲染图像,但这是一个复杂的过程 ...
  • 你不能,基本上不写入文件。 除非有文件,否则不能有FileInputStream或FileChannel 。 如果可能,请确保您的代码与输入源无关 - 根据InputStream和ByteChannel (或任何类型的通道最合适)进行设计。 You can't, without basically writing to a file. Unless there's a file, there can't be a FileInputStream or a FileChannel. If at all pos ...
  • 您总是可以编写File f = new File("anyName") :即使该文件不存在,也不会抛出异常。 但是,如果文件不存在,编写InputStream myini = new FileInputStream("anyName")将抛出FileNotFoundException异常,如文档中所示 。 getResourceAsStream() vs FileInputStream Is the best explanation I have found. Personally after trying ...
  • 我不认为你的问题是数据的分块。 XML数据是纯文本数据 - 分块意味着它被分成几个部分,这些部分被转移到另一个部分。 因此,每个块应该包含可见的纯文本xml数据,这显然不是数据图中所示的情况。 可能是内容是通过gzip压缩编码的,或者它不是纯文本XML而是二进制编码的XML(例如像WBXML)。 您可以从发送的服务器响应头中看到具体类型,尤其是它包含的已使用的mime类型。 I don't think that your problem is the chunking of data. XML data i ...
  • 在iOS上进行异步调用会更好。 这将导致更具响应性的应用程序。 这里有一个简单的例子来从网上下载图像并将其显示在UIImageView : class ViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() if let url = NSURL(string: ...
  • (从服务器上的servlet) 要在不使用html代码的情况下调用call enqueue servlet,可以使用RequestDispatcher并转发请求。 String enqueueURL = "/enqueue"; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(destination); dispatcher.forward(request, response); 要将List发送到另一个ser ...

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的