错误:对于输入字符串:""当我将对象图层添加到我的tilemap时

时间:2016-06-14 03:07:46

标签: java slick2d tiled

我目前正在尝试使用Slick2D渲染我使用Tiled制作的tilemap,一切正常,直到我在tilemap中包含一个对象层。我已经远程搜索了互联网以找到我的困境的答案,似乎大多数其他人都会遇到这个问题,因为他们将对象的宽度和高度字符串留空。在多次浏览我的.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$1.run(CanvasGameContainer.java:69)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.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$1.run(CanvasGameContainer.java:69)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.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很新。

1 个答案:

答案 0 :(得分:0)

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

最好的解决方法是修改Slick2D,使其不需要width元素上的heightobjectgroup属性,并尝试在上游接受该修复,如果它尚未在最新的开发版本中解决过。