[英]Tiled in LibGDX cannot cast java.lang.String to java.lang.Boolean
I'm trying to make a function to check if a cell in Tiled can be passed, by accessing a Boolean custom property I gave each tile. 我试图通过访问我给每个图块提供的布尔自定义属性,使函数检查是否可以传递Tiled中的单元格。 This is (part of) my code.
这是我的代码(的一部分)。
...
public boolean isCellPassable(int column, int row, MapLayer layer) {
boolean canPass = Boolean.valueOf((Boolean) ((TiledMapTileLayer) layer).getCell(column, row).getTile().getProperties().get("can_pass"));
if (canPass == true) {
return true;
}
else {
return false;
}
}
public void displayHUD(ShapeRenderer hud) {
System.out.println(isCellPassable(0, 6, Main.level1.getLayers().get("base")));
...
And even though in the isCellPassable
function I cast it to a Boolean, for some reason I still get this error .. 即使在
isCellPassable
函数中,我也将其isCellPassable
转换为布尔值,但由于某种原因,我仍然收到此错误..
Exception in thread "LWJGL Application" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
.. on the line where I set the value of canPass
. ..在我设置
canPass
值的canPass
。
您可能应该删除对Boolean
的Boolean.valueOf(String)
,并确保选择了Boolean.valueOf(String)
重载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.