简体   繁体   English

尝试实现我的Tilemap时,Java向我抛出错误'对于输入字符串:“”

[英]When trying to implement my Tilemap, Java is throwing me an error ' For input string: “” '

Right now I am facing a problem I just can't seem to find any help on the Internet. 现在我正面临一个问题,我似乎无法在Internet上找到任何帮助。 I am trying to implement my tilemap I made with Tiled into my Slick2D java project, but I can't get around this error code: 我正在尝试将使用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

I just can't find a way to get my head around this. 我只是找不到办法解决这个问题。 I am not working with any inputs which could end up in an input string. 我没有使用任何可能以输入字符串结尾的输入。 I just can't figure out what I'm doing wrong. 我只是不知道我在做什么错。

This is my code: 这是我的代码:

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);
}
}

It might even be helpful to point me somewhere the problem could be, but I just can't find a connection beetween the code and the error. 甚至将问题指向我可能会有所帮助,但我只是找不到代码与错误之间的联系。

Had same issue with an uncorrupted file, checked the Slick2D source. 如果文件未损坏,也有同样的问题,请检查Slick2D源。 This error is caused by attempting to load a map with an object layer whose "width" and "height" properties are undefined or not parseable as Integers in its "objectgroup" XML tag (.tmx files are XML). 此错误是由于尝试加载对象层的地图而导致的,该对象层的“宽度”和“高度”属性未定义或不可解析为“对象组” XML标签中的整数(.tmx文件为XML)。 The Slick2D version of Tiled's Java library expects them (it doesn't use them for anything as far as I can tell - the version I've got ignores map objects entirely in its rendering code) and the Tiled map editor wouldn't normally (if ever) define them - if you really need a bounding box for an object layer it's best computed after loading the map. Tiled的Java库的Slick2D版本期望它们(据我所知,它不用于任何用途-我所获得的版本在其渲染代码中完全忽略了地图对象),而Tiled地图编辑器通常不会(如果有的话)定义它们-如果您确实需要对象层的边界框,则最好在加载地图后进行计算。

Hopefully this'll eventually be fixed, but the simplest workaround is to open up the .tmx file in a text editor and insert width="1" height="1" in every objectgroup tag. 希望最终将解决此问题,但是最简单的解决方法是在文本编辑器中打开.tmx文件,并在每个对象组标记中插入width="1" height="1" This could be automated by first loading the .tmx files into a String, doing a find() or regex search and replace and calling the TiledMap constructor with a " new ByteArrayInputStream(tmxString. getBytes(Charset.forName("UTF-8")) ". 这可以通过首先装载自动化的.tmx文件转换成一个字符串,做一个find()或正则表达式查找和替换和调用TiledMap的构造函数与“ new ByteArrayInputStream(tmxString. getBytes(Charset.forName("UTF-8")) ”。

@Dana Otken, the width="1" height="1" in the .tmx file is necessary, but I've noticed another factor. @Dana Otken,.tmx文件中的width =“ 1” height =“ 1”是必需的,但是我注意到了另一个因素。 If you are indeed using Tiled, you MUST make sure EVERY object in every object layer has whole numbers for the following values: Width, Height, X location, and Y location. 如果确实使用Tiled,则必须确保每个对象层中的每个对象都具有以下值的整数:宽度,高度,X位置和Y位置。 Here's the reason why: an int data type CANNOT handle decimals. 原因如下:int数据类型不能处理小数。 You may recall, that's what the double data type is for. 您可能还记得,这就是double数据类型的用途。 When slick (or lwjgl, I can't remember which) tries to use the parseInt method with a string input, it throws this error, and can't run. 当slick(或lwjgl,我不记得是哪个)尝试将parseInt方法与字符串输入配合使用时,它将引发此错误,并且无法运行。 REMEMBER: Int can't hold a decimal value, and you are using the parseInt method. 记住:Int不能保存十进制值,并且您正在使用parseInt方法。

PS You can't have a fraction of a pixel, so even if you did have a double value with an actual decimal, it wouldn't make sense because pixels can't be further divided. PS您不能有一个像素的小数部分,因此即使您有一个带有实际小数的双精度值,也没有意义,因为无法进一步划分像素。

Hope this helps! 希望这可以帮助!

A similar SO page here: https://gamedev.stackexchange.com/questions/93607/how-import-and-draw-a-tiledmap-with-slick2d/122051#122051 此处类似的SO页面: https : //gamedev.stackexchange.com/questions/93607/how-import-and-draw-a-tiledmap-with-slick2d/122051#122051

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:对于输入字符串:“”当我将对象图层添加到我的tilemap时 - ERROR:For input string: “” when I add object layer to my tilemap 尝试在我的 Java Spring ZDB974238714CA8DE6434A7CE1DFZ83A 中实现 Swagger 时出现错误消息 - Error message when trying to implement Swagger in my Java Spring API 为什么drJava在我的String上给我一个错误? - Why is drJava throwing me an error here on my String? 为什么当我从用户那里获得输入时,我的 java 代码会抛出错误? - Why is my java code throwing an error when I get input from the user? 尝试在Java中实现桥接模式时出错 - Error when trying to implement the Bridge pattern in Java 将字符串转换为整数会向我抛出错误:( - Converting string to integer is throwing an error at me :( 尝试在Java中实现Iterable时使用泛型时出错 - Error when using generics when trying to implement Iterable in Java Java:尝试运行我的字符串函数时,获取字符串索引超出范围错误 - Java: Getting a string index out of bounds error when trying to run my string functions 尝试将其添加到我的JFrame时,KeyListener总是给我一个错误 - KeyListener always gives me an error when trying to add it to my JFrame Java spring Hibernate:尝试实现多对一关系时出错 - Java spring Hibernate : Error when trying to implement a many to one relationship
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM