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 benull
. I want to replace thenull
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
最满意答案
问题已经解决了! 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的InputStream(InputStream from a URL)[2023-12-18]
使用适合的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 ...
-
如何获得https的分块Push Servlet的InputStream?(How to get InputStream of an https, chunked Push Servlet?)[2022-04-06]
问题已经解决了! 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: ...
-
如何使用Java将一个servlet调用到GWT中的另一个servlet(How to call one servlet to another servlet in GWT Using Java)[2020-02-10]
(从服务器上的servlet) 要在不使用html代码的情况下调用call enqueue servlet,可以使用RequestDispatcher并转发请求。 String enqueueURL = "/enqueue"; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(destination); dispatcher.forward(request, response); 要将List发送到另一个ser ...