objective-c - program terminating with uncaught exception of type NSException
问题描述
I am trying to go through an xml file and display the contents
int main(int argc, const char * argv[])
{
NSString *xmlPath = [[NSBundle mainBundle] pathForResource:@"xml" ofType:@"xml"];
NSString *xml = [NSString stringWithContentsOfFile:xmlPath encoding:NSUTF8StringEncoding error:nil];
NSXMLDocument *xmlDocument = [[NSXMLDocument alloc] initWithXMLString:xml options:0 error:nil];
NSMutableArray *array = [NSMutableArray array];
for (NSXMLElement *node in [xmlDocument.rootElement nodesForXPath:@"//app" error:nil])
{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
NSMutableArray *photos = [NSMutableArray array];
for (NSXMLElement *subNode in node.children)
{
if ([subNode.name isEqualToString:@"address"])
[photos addObject:subNode.stringValue];
else
[dict setObject:subNode.stringValue forKey:subNode.name];
}
[dict setObject:photos forKey:@"address"];
[array addObject:dict];
}
NSLog(@"%@", array);
return 0;
}
But I'm getting an error in this line
NSXMLDocument *xmlDocument = [[NSXMLDocument alloc] initWithXMLString:xml options:0 error:nil];
The error says libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
please help
解决方案
检查xml NSString 是否为 nil
推荐阅读
- android - RemoteViews setImageViewBitmap()不起作用
- dialogflow-es - 如何在 Dialogflow 数字字符串实体中支持“双”和“三”?
- azure-webjobs - 将 Azure 主题消息接收到 Web 作业中?
- php - Laravel simple validation doens't work on resource method
- python - Python Bot报错原因及解决方法
- exchangelib - Python exchangelib 推送通知?
- html - 没有连接到模型或链接的轨道形式
- spring-security - 如何向我的服务提供商验证角色/权限信息 wso2 身份服务器?
- html - 悬停不适用于列表中的所有元素
- vba - 在 MS Word VBA 中,使用出现的数字插入对编号项目编号的交叉引用的方法