Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

java - I keep getting a "The operator == is undefined for the argument type(s) boolean, int" and have no idea how to fix it

I keep getting a "The operator == is undefined for the argument type(s) boolean, int" in this bit of code at line 3:

    public void loadState(int i)
  {
      if (statesSaved[i] == 0)
      {
        return;
      }
      List list = TMIUtils.getMinecraft().h.at.e;
      for (int j = 0; j < 44; j++)
        {
          sx slot = (sx)list.get(j + 1);
          slot.c(null);
          ul itemstack = TMIUtils.copyStack(states[i][j]);
          if ((itemstack == null) || (itemstack.c < 0) || (itemstack.c >= sv.f.length) || (sv.f[itemstack.c] == null))
            continue;
          slot.c(itemstack);
    }
  }

I have no idea why this happens, since i have another class file with the same thing where there is no error.

Here is my full class file if it helps:

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.client.Minecraft;

public class TMIConfig
{
  public static final String VERSION = "1.7.2 2011-07-01";
  public static final int NUM_SAVES = 7;
  public static final int INVENTORY_SulE = 44;
  public static boolean isModloaderEnabled = false;
  private static TMIConfig instance;
  private static List items = new ArrayList();
  private static HashSet toolIds;
  private static HashSet nonUnlimitedIds;
  private Map settings;
  private static ul[][] states = new ul[7][44];
  private static boolean[] statesSaved = new boolean[7];
  private static HashSet excludeIds;

  public TMIConfig()
  {
    this.settings = new LinkedHashMap();
    this.settings.put("enable", "true");
    this.settings.put("enablemp", "false");
    this.settings.put("give-command", "/give {0} {1} {2}");
    for (int i = 0; i < getNumSaves(); i++)
    {
      this.settings.put(new StringBuilder().append("save-name").append(i + 1).toString(), new StringBuilder().append("").append(i + 1).toString());
    }

    for (int j = 0; j < getNumSaves(); j++)
    {
      this.settings.put(new StringBuilder().append("save").append(j + 1).toString(), "");
    }

    instance = this;
  }

  public static boolean isMultiplayer()
  {
    return TMIUtils.getMinecraft().f.I;
  }

  public static TMIConfig getInstance()
  {
    if (instance == null)
    {
      new TMIConfig();
    }
    return instance;
  }

  public Map getSettings()
  {
    return this.settings;
  }

  public List getItems()
  {
    return items;
  }

  public int getNumSaves()
  {
    return 7;
  }

  public boolean isStateSaved(int i)
  {
    return statesSaved[i];
  }

  public ul[] getState(int i)
  {
    return states[i];
  }

  public boolean getBooleanSetting(String s)
  {
    return Boolean.parseBoolean((String)this.settings.get(s));
  }

  public boolean isEnabled()
  {
    return ((isMultiplayer()) && (getBooleanSetting("enablemp"))) || ((!isMultiplayer()) && (getBooleanSetting("enable")));
  }

  public void toggleEnabled()
  {
    String s = isMultiplayer() ? "enablemp" : "enable";
    this.settings.put(s, Boolean.toString(!getBooleanSetting(s)));
  }

  public void setEnabled(boolean flag)
  {
    String s = isMultiplayer() ? "enablemp" : "enable";
    this.settings.put(s, Boolean.toString(flag));
  }

  public static boolean isItemIncluded(int i)
  {
    return !excludeIds.contains(Integer.valueOf(i));
  }

  public static boolean isTool(sv item)
  {
    return toolIds.contains(Integer.valueOf(item.br));
  }

  public static boolean canItemBeUnlimited(sv item)
  {
    return !nonUnlimitedIds.contains(Integer.valueOf(item.br));
  }

  public boolean areDamageVariantsShown()
  {
    if (isMultiplayer())
    {
      String s = (String)getSettings().get("give-command");
      return s.contains("{3}");
    }

    return true;
  }

  public void clearState(int i)
  {
    for (int j = 0; j < 44; j++)
    {
      states[i][j] = null;
      statesSaved[i] = false;
    }

    this.settings.put(new StringBuilder().append("save").append(i + 1).toString(), "");
  }

  public void loadState(int i)
  {
      if (statesSaved[i] == 0)
      {
        return;
      }
      List list = TMIUtils.getMinecraft().h.at.e;
      for (int j = 0; j < 44; j++)
        {
          sx slot = (sx)list.get(j + 1);
          slot.c(null);
          ul itemstack = TMIUtils.copyStack(states[i][j]);
          if ((itemstack == null) || (itemstack.c < 0) || (itemstack.c >= sv.f.length) || (sv.f[itemstack.c] == null))
            continue;
          slot.c(itemstack);
    }
  }

  public void saveState(int i)
  {
    List list = TMIUtils.getMinecraft().h.at.e;
    for (int j = 0; j < 44; j++)
    {
      states[i][j] = TMIUtils.copyStack(((sx)list.get(j + 1)).a());
    }

    this.settings.put(new StringBuilder().append("save").append(i + 1).toString(), encodeState(i));
    statesSaved[i] = true;
  }

  public String encodeState(int i)
  {
    StringBuilder stringbuilder = new StringBuilder();
    for (int j = 0; j < 44; j++)
    {
      if (states[i][j] != null)
      {
        stringbuilder.append(states[i][j].c);
        stringbuilder.append(":");
        stringbuilder.append(states[i][j].a);
        stringbuilder.append(":");
        stringbuilder.append(states[i][j].i());
      }
      stringbuilder.append(",");
    }

    return stringbuilder.toString();
  }

  public void decodeState(int i, String s)
  {
    if (s.trim().equals(""))
    {
      statesSaved[i] = false;
    }
    else {
      String[] as = s.split(",", 0);
      for (int j = 0; (j < as.length) && (j < states[i].length); j++)
      {
        String[] as1 = as[j].split(":");
        if (as1.length != 3)
        {
          continue;
        }
        try
        {
          states[i][j] = new ul(Integer.parseInt(as1[0]), Integer.parseInt(as1[1]), Integer.parseInt(as1[2]));
        }
        catch (Exception exception)
        {
          System.out.println(exception);
        }
      }

      statesSaved[i] = true;
    }
  }

  static
  {
    toolIds = new HashSet();
    for (int i = 1; i <= 3; i++)
    {
      toolIds.add(Integer.valueOf(i + 256));
    }

    for (int j = 11; j <= 23; j++)
    {
      toolIds.add(Integer.valueOf(j + 256));
    }

    for (int k = 27; k <= 30; k++)
    {
      toolIds.add(Integer.valueOf(k + 256));
    }

    for (int l = 34; l <= 38; l++)
    {
    toolIds.add(Integer.valueOf(l + 256));
    }

    for (int m = 42; m <= 61; m++)
    {
    toolIds.add(Integer.valueOf(m + 256));
    }

    toolIds.add(Integer.valueOf(359));
    toolIds.add(Integer.valueOf(346));

    nonUnlimitedIds = new HashSet();
    nonUnlimitedIds.add(Integer.valueOf(358));
    excludeIds = new HashSet();
    excludeIds.add(Integer.valueOf(9));
    excludeIds.add(Integer.valueOf(11));
    excludeIds.add(Integer.valueOf(63));
    excludeIds.add(Integer.valueOf(64));
    excludeIds.add(Integer.valueOf(68));
    excludeIds.add(Integer.valueOf(71));
    excludeIds.add(Integer.valueOf(74));
    excludeIds.add(Integer.valueOf(75));
    excludeIds.add(Integer.valueOf(59));
    excludeIds.add(Integer.valueOf(83));
    excludeIds.add(Integer.valueOf(55));
    excludeIds.add(Integer.valueOf(26));
    excludeIds.add(Integer.valueOf(93));
    excludeIds.add(Integer.valueOf(94));
    try
    {
      Class.forName("mod_RedPowerWiring");
      excludeIds.add((Integer)ModLoader.getPrivateValue(mod_RedPowerWiring.class, null, "InsWireID"));
      excludeIds.add((Integer)ModLoader.getPrivateValue(mod_RedPowerWiring.class, null, "CableID"));
    }
    catch (Exception exception)
    {
    }
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Java, unlike C which allows a great deal of latitude in treating variables as differing types in certain circumstances, is a bit more strict in what you're allowed to do. Your two problematic lines are:

private static boolean[] statesSaved = new boolean[7];
if (statesSaved[i] == 0)

You need to recode that last one as:

if (!statesSaved[i])

And, please, if you value the sanity of those who will maintain your code, don't use things like:

if (statesSaved[i] == false)

There should never be any need to compare a boolean explicitly. You should instead choose intelligent names like hasSavedState or isBroken so that expressions like:

if (isBroken)

or:

while (!finished)

make sense in English. This will enhance the readability of your code greatly.

In any case, since the explicit comparison of a boolean results in another boolean, where would you stop. The time-honored tradition of reductio ad absurdum would require code like:

if (((finished == true) == true) == true) ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...