现在,我正面临一个问题,我似乎无法在Internet上找到任何帮助。我正在尝试将使用Tiled制作的tilemap实施到Slick2D java项目中,但是无法解决此错误代码:

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 simpleslickgame.SpielTest.init(SpielTest.java:36)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
at simpleslickgame.SpielTest.main(SpielTest.java:25)

Fri Dec 26 22:47:27 CET 2014 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 simpleslickgame.SpielTest.init(SpielTest.java:36)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
at simpleslickgame.SpielTest.main(SpielTest.java:25)
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)
... 6 more


我只是找不到办法解决这个问题。我没有使用任何可能以输入字符串结尾的输入。我只是不知道我在做什么错。

这是我的代码:

package simpleslickgame;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;

public class SpielTest extends BasicGame
{
public TiledMap map;

public SpielTest()
{
    super("Test");
}

public static void main(String[] arguments)
{
    try
    {
        AppGameContainer app = new AppGameContainer(new SpielTest());
        app.setDisplayMode(1000, 800, false);
        app.start();
    }
    catch (SlickException e)
    {
        e.printStackTrace();
    }
}

@Override
public void init(GameContainer container) throws SlickException
{
    map=new TiledMap("res/Slickesdingbruder.tmx");
}

@Override
public void update(GameContainer container, int delta) throws SlickException
{
}

public void render(GameContainer container, Graphics g) throws SlickException
{
    map.render(0, 0);
}
}


甚至将问题指向我可能会有所帮助,但我只是找不到代码和错误之间的联系。

最佳答案

如果文件未损坏,也有同样的问题,请检查Slick2D源。此错误是由于尝试加载对象层的地图而导致的,该对象层的“宽度”和“高度”属性未定义或无法解析为“对象组” XML标签中的整数(.tmx文件为XML)。 Tiled的Java库的Slick2D版本期望它们(据我所知它不会将它们用于任何东西-我所获得的版本在其渲染代码中完全忽略了地图对象),而Tiled地图编辑器通常不会( (如果有的话)定义它们-如果您确实需要对象层的边界框,则最好在加载地图后进行计算。

希望最终将解决此问题,但是最简单的解决方法是在文本编辑器中打开.tmx文件,并在每个对象组标记中插入width="1" height="1"。通过首先将.tmx文件加载到字符串中,执行find()或正则表达式搜索并替换并使用“ TiledMap”调用new ByteArrayInputStream(tmxString. getBytes(Charset.forName("UTF-8"))构造函数,可以实现自动化。

10-08 15:10