Search code examples
javaslick2dtiled

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


I am currently trying to render a tilemap I made with Tiled using Slick2D, and everything works fine until I include an object layer in my tilemap. I have searched the internet far and wide for an answer to my dilemma, and it seems that most other people get this problem because they leave the object width and height strings empty. After looking through my .tmx file several times, I am positive that all of my height and width values contain a number greater than zero.

Here is my .tmx file:

`<?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>

`

Here is the error I receive:

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

I would greatly appreciate it if someone could point out anything I did wrong. I'm rather new to Slick2D and tilemaps.


Solution

  • The problem is likely that the objectgroup element is missing width and height attributes. These attributes used to be written out by Tiled a long time ago, but they never made sense. Slick2D fails to detect that they are not there and tries to parse an empty string as a number, which raises a NumberFormatException that is left uncaught.

    The best fix would be to modify Slick2D so that it does not need the width and height attributes on the objectgroup element, and try to get that fix accepted upstream, if it hasn't been already addressed in the latest development version.