gpt4 book ai didi

java - 我一直收到 "The operator == is undefined for the argument type(s) boolean, int"并且不知道如何修复它

转载 作者:行者123 更新时间:2023-11-29 09:45:31 28 4
gpt4 key购买 nike

我不断收到“运算符 == 对于参数类型 boolean、int 未定义”在第 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);
}
}

我不知道为什么会这样,因为我有另一个没有错误的相同内容的类文件。

如果有帮助,这是我的完整类(class)文件:

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

最佳答案

Java 与 C 不同,C 允许在某些情况下将变量视为不同类型的很大自由度,Java 在允许您做的事情上更加严格。你的两条有问题的线是:

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

您需要将最后一个重新编码为:

if (!statesSaved[i])

而且,如果您重视那些将维护您的代码的人的理智,请不要使用以下内容:

if (statesSaved[i] == false)

应该永远不需要显式地比较 boolean 值。您应该改为选择像 hasSavedStateisBroken 这样的智能名称,以便像这样的表达式:

if (isBroken)

或:

while (!finished)

用英语说得通。这将大大增强代码的可读性。

无论如何,由于 boolean 值的显式比较会导致另一个 boolean 值,您会在哪里停下来。历史悠久的反证法传统需要如下代码:

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

关于java - 我一直收到 "The operator == is undefined for the argument type(s) boolean, int"并且不知道如何修复它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7733982/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com