Java 重复局部变量“;附「;错误?

Java 重复局部变量“;附「;错误?,java,Java,我试图调试代码的一部分,但出现了“复制局部变量”错误。我该怎么解决这个问题呢?我不确定错误是什么,所以我在这里问 public JumpPlusPlayer(JumpPlus plugin, Player p) { loadPermissions(p, plugin); fillConfig(plugin); } protected void loadPermissions(Player p, JumpPlus plugin) { HashSet<Pe

我试图调试代码的一部分,但出现了“复制局部变量”错误。我该怎么解决这个问题呢?我不确定错误是什么,所以我在这里问

public JumpPlusPlayer(JumpPlus plugin, Player p) {
    loadPermissions(p, plugin);
    fillConfig(plugin);
  }

  protected void loadPermissions(Player p, JumpPlus plugin) {
      HashSet<PermissionAttachmentInfo> perms = new HashSet<PermissionAttachmentInfo>();
    PermissionAttachment attach;
    if (plugin.usingPEX) {
      PermissionUser user = PermissionsEx.getUser(p);
      String world = p.getWorld().getName();
      attach = new PermissionAttachment(plugin, p);
      for (String perm : user.getPermissions(world)) {
        String expression = user.getMatchingExpression(perm, world);
        perms.add(new PermissionAttachmentInfo(p, perm, attach, user.explainExpression(expression)));
      }
    } else {
      perms = (HashSet<PermissionAttachmentInfo>) p.getEffectivePermissions();
    }

    for (PermissionAttachmentInfo attach : perms) {
      String perm = attach.getPermission();
      if (perm.contains("jumpplus.config.")) {
        String[] aux = perm.split("jumpplus.config.");
        aux = aux[1].split("-");
        if (aux[0].equals("hspeed"))
          this.hSpeed = Double.valueOf(Double.parseDouble(aux[1]));
        else if (aux[0].equals("vspeed"))
          this.vSpeed = Double.valueOf(Double.parseDouble(aux[1]));
        else if (aux[0].equals("maxjumps"))
          this.maxJumps = Integer.valueOf(Integer.parseInt(aux[1]));
        else if (aux[0].equals("maxfreejumps"))
          this.maxFreeJumps = Integer.valueOf(Integer.parseInt(aux[1]));
        else if (aux[0].equals("jumpcost"))
          this.jumpCost = Integer.valueOf(Integer.parseInt(aux[1]));
        else if (aux[0].equals("fallmodifier"))
          this.fallModifier = Integer.valueOf(Integer.parseInt(aux[1]));
        else if (aux[0].equals("particleeffect"))
          this.particleEffect = Boolean.valueOf(Boolean.parseBoolean(aux[1]));
        else if (aux[0].equals("defaultstate"))
          this.enable = Boolean.valueOf(Boolean.parseBoolean(aux[1]));
      }
    }
  }
公共JumpPlusPlayer(JumpPlus插件,播放器p){
loadPermissions(p,plugin);
fillConfig(插件);
}
受保护的无效加载权限(播放器p、JumpPlus插件){
HashSet perms=新HashSet();
许可证附件;
if(plugin.usingPEX){
PermissionUser=PermissionsEx.getUser(p);
字符串world=p.getWorld().getName();
附件=新许可附件(插件,p);
for(字符串perm:user.getPermissions(world)){
字符串表达式=user.getMatchingExpression(perm,world);
添加(新权限附件信息(p,perm,attach,user.explainExpression(expression));
}
}否则{
perms=(HashSet)p.getEffectivePermissions();
}
用于(权限附件信息附件:perms){
字符串perm=attach.getPermission();
if(perm.contains(“jumpplus.config”)){
字符串[]aux=perm.split(“jumpplus.config”);
aux=aux[1]。拆分(“-”);
if(aux[0].equals(“hspeed”))
this.hSpeed=Double.valueOf(Double.parseDouble(aux[1]);
else if(辅助[0].equals(“vspeed”))
this.vSpeed=Double.valueOf(Double.parseDouble(aux[1]);
else if(aux[0].equals(“maxjumps”))
this.maxJumps=Integer.valueOf(Integer.parseInt(aux[1]);
else if(aux[0].equals(“maxfreejumps”))
this.maxFreeJumps=Integer.valueOf(Integer.parseInt(aux[1]);
else if(辅助[0]。等于(“跳转成本”))
this.jumpCost=Integer.valueOf(Integer.parseInt(aux[1]);
else if(辅助[0].equals(“fallmodifier”))
this.fallModifier=Integer.valueOf(Integer.parseInt(aux[1]);
else if(aux[0].equals(“particleeffect”))
this.particleEffect=Boolean.valueOf(Boolean.parseBoolean(aux[1]);
else if(aux[0].equals(“defaultstate”))
this.enable=Boolean.valueOf(Boolean.parseBoolean(aux[1]);
}
}
}
我该怎么解决这个问题呢

不在同一范围内声明局部变量两次吗

在增强型for循环中使用不同的局部变量名称,或者将第一个局部变量的声明移动到
if
语句中:

PermissionAttachment attach = new PermissionAttachment(plugin, p);

(您不能在
if
语句之外使用它,那么为什么要在开始时声明它?

问题在于您的
loadPermissions
方法,特别是这两行:

PermissionAttachment attach;
for (PermissionAttachmentInfo attach : perms) {

第一行声明一个名为
attach
的局部变量(仅存在于该方法调用内部的变量)。第二行还声明了一个名为
attach
的局部变量,但由于该变量已经存在,因此无法执行此操作。您需要为其中一个选择一个不同的名称。

粘贴在此处stacktrace of error,显示抛出它的代码行。一个合适的IDE可以帮助您()@defaultlocale这是一个编译错误,因此不会有stacktrace。在代码中搜索
attach
。这与错误消息有什么关系?@AnthonyGrist抱歉,没有仔细阅读帖子