当前位置: 首页 > 知识库问答 >
问题:

未定义参数类型boolean、int的运算符!=

訾稳
2023-03-14

在我的代码中,我一直得到这样的错误:操作符!=对于参数类型boolean和int是未定义的,我不知道该怎么做来修复它。该错误出现在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]);
        }
      }

共有2个答案

邢财
2023-03-14

在某些语言中,boolean类型与int密切相关,因此将一个boolean与0进行比较是有意义的。在Java,它们是完全不同的类型。boolean只能与其他boolean表达式进行比较。

若要测试布尔值是否为false,请使用!this.ctexture[i]。对于true,只需使用布尔值。

邴兴为
2023-03-14

您有:

private boolean[] ctexture = new boolean[16];

那么你就会:

if(this.ctexture[i] != 0)
        ↑              ↑
     boolean          int

在Java中,你不能这样做,0是intthis.ctexture[i]boolean

您可能应该这样做:

if(this.ctexture[i]) //if true

您在其他地方也有无效的比较,请同时修复它们

 类似资料:
  • 我的Java代码没有什么问题。我正在使用下面的代码,但Eclipse总是提示相同的消息“参数类型Test1,int的运算符未定义”。但是如果我将代码更改为“System.out.println(test1”“100);”或“System.out.println”(“100 test1”)或“System.out.println(100”“test1);”,没有问题。 有人对此有想法吗?请帮忙。多谢

  • 下面的方法中不断出现错误“The operator-is undefined for The argument type double[],double”,我不知道为什么或如何修复它。 特别是在以下行:“如果((targetX-x)

  • 我这里有这个代码: 但我得到了错误信息: 接线员 为什么呢?如何修复代码? 以下是代码的文本形式:

  • 我是新来的处理,我有这个问题。我一直收到下面代码中粗体部分的错误消息。我的语法错了吗?

  • 问题内容: 我得到这个错误 问题答案: 具有无效的返回类型。更改方法的返回类型以返回值

  • 问题内容: 我正在学习Java,它来自C语言,并且发现该类型的语言之间有一个有趣的区别。在C语言中没有/,因此我们需要使用数字类型来表示布尔逻辑()。 我猜在Java中不起作用: 也不会通过类型转换更改条件: 因此,除了要做类似的事情: 还有其他方法可以对类型进行C-ish逻辑检查吗?只是想知道是否有任何Java技巧可以在这样的非布尔类型上使用布尔逻辑。 编辑: 上面的示例非常简单,并且使自己陷入