2013-02-28 20 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的局部變量,但既然已經存在,它不能這樣做。你需要爲他們中的一個選擇一個不同的名字。