ZhouWeikuan / cocos2d

cocos2d for android, based on cocos2d-android-0.82, and now ported from cocos2d-iphone 0.99.4. The googlecode address is here: http://code.google.com/p/cocos2d-android-1/ . There are several demos to watch.
610 stars 291 forks source link

CCTMXMapInfo NumberFormatException #39

Open ghost opened 12 years ago

ghost commented 12 years ago

parseXMLFile() does not display a friendly error message, the stacktrace().toString() method does not provide any useful information. There are a number of opportunities for a NumberFormatException.

ghost commented 12 years ago

Getting the offsetPosition for the objectgroup can throw an Exception when attempting to cast a null value to an integer. THis is caused when there is no x or y attributes in the objectgroup key. This will result in the TMXMapInfo objectGroup information not being parsed, and map.objectGroupNamed("group name") will not return any groups. I fixed in my build by changing line 289 from: positionOffset.x = Integer.parseInt( attributes.getValue( "x" ) ) * tileSize.width; positionOffset.y = Integer.parseInt( attributes.getValue( "y" ) ) * tileSize.height; objectGroup.positionOffset = positionOffset;

TO: try { positionOffset.x = Integer.parseInt( attributes.getValue( "x" ) ) * tileSize.width; positionOffset.y = Integer.parseInt( attributes.getValue( "y" ) ) * tileSize.height;

      objectGroup.positionOffset = positionOffset;
    }
    catch( Exception e )
    {
      ccMacros.CCLOG( LOG_TAG, "TMXFile: objectgroup does not have a defined x or y value. Defaulting to 0." );
      objectGroup.positionOffset = CGPoint.zero();
    }