2013-02-28 48 views
-2

我想调试代码的一部分,但有一个“重复的局部变量”错误。我将如何解决这个问题?我不确定错误是什么,所以我在这里问。重复的局部变量“附加”错误?

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])); 
     } 
    } 
    } 
+0

粘贴这里错误的堆栈跟踪,显示它的代码行。 – 2013-02-28 09:38:11

+0

体面的IDE可以帮助你(http://www.eclipse.org/downloads/) – Apurv 2013-02-28 09:38:46

+1

@defaultlocale这是一个编译错误,所以不会有堆栈跟踪。 – 2013-02-28 09:41:14

回答

2

我将如何得到解决解决这个?

嗯,不要在同一范围内声明两次局部变量?

无论是在您的增强的for循环使用不同的局部变量名,或移动的第一个宣言到if声明:

PermissionAttachment attach = new PermissionAttachment(plugin, p); 

(你不使用它外面的if声明,那么,为什么在一开始声明它)

0

的问题是与你的loadPermissions方法,尤其是这两行:

PermissionAttachment attach; 
for (PermissionAttachmentInfo attach : perms) { 

第一行声明了一个名为attach的局部变量(只存在于该方法调用中的变量)。第二行声明一个名为attach的局部变量,但既然已经存在,它不能这样做。你需要为他们中的一个选择一个不同的名字。