我不断遇到错误!=对于参数类型布尔值不确定在我的代码上,我不知道该如何解决它。该错误出现在Eclipse以及发射
中一些帮助将不胜感激:)谢谢!
private boolean[] ctexture = new boolean[16];
public boolean[] flipTopBottom = new boolean[16];
this.ctexture[id] = connectedTexture;
@SideOnly(Side.CLIENT)
public Icon getIcon(int par1, int par2)
{
if ((par1 <= 1) && (this.flipTopBottom[(par2 & 0xF)] != 0) //The error occurs here// && ((this.icons[(par2 & 0xF)] instanceof IconConnectedTexture))) {
return new IconConnectedTextureFlipped((IconConnectedTexture)this.icons[(par2 & 0xF)]);
}
return this.icons[(par2 & 0xF)];
}
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
for (int i = 0; i < 16; i++) {
if ((this.texture[i] != null) && (this.texture[i] != "")) {
if (this.ctexture[i] != 0) { //It also occurs here
this.icons[i] = new IconConnectedTexture(par1IconRegister, this.texture[i]);
} else {
this.icons[i] = par1IconRegister.registerIcon(this.texture[i]);
}
}
你有:
private boolean[] ctexture = new boolean[16];
然后您要做:
if(this.ctexture[i] != 0)
↑ ↑
boolean int
在Java中,您不能这样做,0是int
,this.ctexture[i]
是boolean
。
您可能应该这样做:
if(this.ctexture[i]) //if true
您在其他地方也有无效的比较,请修复它们
在某些语言中,布尔类型与int密切相关,因此比较布尔值为0是有道理的。在Java中,它们是完全不同的类型。布尔人只能与其他布尔表达式进行比较。
要测试布尔值为false,请使用!this.ctexture[i]
。对于TRUE,只需使用布尔值。
flipToBottom
是布尔值的数组,但您尝试将一个条目(布尔值)与整数进行比较。
if ((par1 <= 1) && (this.flipTopBottom[(par2 & 0xF)] != 0)
之类的东西 if ((par1 <= 1) && !this.flipTopBottom[(par2 & 0xF)])
可能是您所追求的。(一般会议是不说if (variable == true)
或if (variable == false)
。而不是if(variable)
或if (!variable)
。