Hashmap 崩溃 Eclipse
我试图通过解析 Android 中的 plist 文件来加载哈希图,使用这里的 plist 解析器: https:// github.com/ZhouWeikuan/cocos2d。 这在过去工作得很好,但最近我的程序在使用这个哈希图时(解析后)出现了空指针异常。 当我尝试调试时,Eclipse 开始表现得很奇怪。解析器返回哈希图,我可以在变量视图中查看它的值。当我跨过分配给“worldMap”的线时,Eclipse 挂起。当尝试在调试模式下查看 worldMap 的值时,我可以看到一个空行但没有值 - 最终 eclipse 崩溃。
Map worlds = (Map)getWorlds().get("Worlds");
Map worldMap = (Map)worlds.get(String.valueOf(world));
Map levels = (Map)worldMap.get("Levels");
然而,当正常运行程序时,空指针异常会在这些行之后出现。 另外,当我尝试调试时,它不会总是在同一位置崩溃,所以我很难找到这个错误的根源......
有人知道发生了什么事吗?
I'm trying to load a hashmap by parsing a plist file in Android, using the plist parser from here: https://github.com/ZhouWeikuan/cocos2d.
This has been working fine in the past, but recently my program has been getting null-pointer exceptions when using this hashmap (after parsing).
When I try to debug, eclipse starts acting weird. The parser returns the hashmap and I can look over it's value in the variables view. When I step over the line that's assigning to 'worldMap', eclipse hangs. When trying to see worldMap's value in debug mode, I can see an empty line but no value - eventually eclipse crashes.
Map worlds = (Map)getWorlds().get("Worlds");
Map worldMap = (Map)worlds.get(String.valueOf(world));
Map levels = (Map)worldMap.get("Levels");
However, when running the program normally the null-pointer exception comes later on, past these lines.
Also, when I'm trying to debug, It won't always crash at the same location so I'm having a really hard time finding the source of this bug...
Does anyone know whats going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法确切地告诉您发生了什么,但 NullPointerException 肯定是一个很大的提示。
在上面示例中的每行代码后面添加一些空检查,我打赌您将能够很快找到错误:
Can't tell you for certain what is going on, but the NullPointerException is sure a big hint.
Add in some null checks after each line of code in your above example and I bet you will be able to track down the error pretty fast: