ERROR:For input string: "" when I add object layer to my tilemap

ERROR:For input string: "" when I add object layer to my tilemap

我目前正在尝试使用 Slick2D 渲染我使用 Tiled 制作的瓷砖地图,并且一切正常,直到我在我的瓷砖地图中包含一个对象层。我在互联网上广泛搜索以寻找解决我困境的答案,似乎大多数其他人都会遇到这个问题,因为他们将对象宽度和高度字符串留空。多次查看我的 .tmx 文件后,我确信我所有的高度和宽度值都包含一个大于零的数字。

这是我的 .tmx 文件:

`<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="isometric" renderorder="right-down" width="45" height="45" tilewidth="64" tileheight="32" nextobjectid="331">
 <tileset firstgid="1" name="grassland_tiles" tilewidth="64" tileheight="32" tilecount="672" columns="16">
  <image source="../../../../../Downloads/grassland_tiles.png" trans="ffffff" width="1024" height="1344"/>
 </tileset>
 <layer name="Bottom" width="45" height="45">
  <data encoding="base64" compression="gzip">
   H4sIAAAAAAAAC+3DQQ0AAAwDoat/01OxHySsmqqqqqqqqqr6/gBaFaajpB8AAA==
  </data>
 </layer>
 <layer name="Top" width="45" height="45">
  <data encoding="base64" compression="gzip">
   H4sIAAAAAAAAC+3DsQkAAAgDsL7t9y4FH3BMIAnAv2kAAAAAAADgLLnS8aKkHwAA
  </data>
 </layer>
 <objectgroup name="Object Layer 1">
  <object id="327" x="96" y="96" width="96" height="96"/>
  <object id="328" x="468" y="1106"/>
  <object id="329" x="141.333" y="125.333"/>
 </objectgroup>
</map>

`

这是我收到的错误:

Mon Jun 13 22:21:27 EDT 2016 ERROR:For input string: ""
    java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at org.newdawn.slick.tiled.TiledMap$ObjectGroup.<init>(TiledMap.java:1008)
    at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:688)
    at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:106)
    at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:90)
    at GameClass.init(GameClass.java:27)
    at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
    at org.newdawn.slick.CanvasGameContainer.run(CanvasGameContainer.java:69)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access0(Unknown Source)
    at java.awt.EventQueue.run(Unknown Source)
    at java.awt.EventQueue.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Mon Jun 13 22:21:27 EDT 2016 ERROR:Failed to parse tilemap
org.newdawn.slick.SlickException: Failed to parse tilemap
    at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:695)
    at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:106)
    at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:90)
    at GameClass.init(GameClass.java:27)
    at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
    at org.newdawn.slick.CanvasGameContainer.run(CanvasGameContainer.java:69)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access0(Unknown Source)
    at java.awt.EventQueue.run(Unknown Source)
    at java.awt.EventQueue.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at org.newdawn.slick.tiled.TiledMap$ObjectGroup.<init>(TiledMap.java:1008)
    at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:688)
    ... 19 more
Mon Jun 13 22:21:27 EDT 2016 INFO:Starting display 1920x1001

如果有人能指出我做错的地方,我将不胜感激。我对 Slick2D 和 tilemaps 比较陌生。

问题可能是 objectgroup 元素缺少 widthheight 属性。很久以前,这些属性曾经被 Tiled 写出来,但它们从来没有意义。 Slick2D 无法检测到它们不存在并尝试将空字符串解析为数字,这会引发未捕获的 NumberFormatException

最好的解决方法是修改 Slick2D,使其不需要 objectgroup 元素上的 widthheight 属性,并尝试让上游接受该修复,如果在最新的开发版本中还没有解决。