Hashmap crashing eclipse
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));
Ma开发者_开发问答p 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?
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:
Map whatEverThisIs = (Map)getWorlds();
if (whatEverThisIs == null) {
/* Do something here */
}
Map worlds = (Map)whatEverThisIs.get("Worlds");
if (worlds == null) {
/* Do something here */
}
Map worldMap = (Map)worlds.get(String.valueOf(world));
if (worldMap == null) {
/* Do something here */
}
Map levels = (Map)worldMap.get("Levels");
if (levels == null) {
/* Do something here */
}
精彩评论