2012-12-18 4 views
0

여기 요아킴의 솔루션 후 코드입니다 :자바 라벨과 휴식 오류

Scripts\OHDHerblaw.java:109: error: undefined label: label1084 if (getInventoryCount(new int[] { this.Herb }) == 0) if (getInventoryCou nt(new int[] { this.Unfinished }) == 0) if (getInventoryCount(new int[] { this.I dentified }) == 0) break label417; if (getInventoryCount(new int[] { this.Vials }) != 0) if (getInventoryCount(new int[] { this.Identified }) != 0) { if (getIn ventoryCount(new int[] { this.Vials }) != 0) if (getInventoryCount(new int[] { t his.Identified }) != 0) break label1084; if (getInventoryCount(new int[] { this. Unfinished }) != 0)

Scripts\OHDHerblaw.java:110: error: undefined label: label1084 break label1084; }

Scripts\OHDHerblaw.java:201: error: undefined label: label1391 break label1391;

Scripts\OHDHerblaw.java:202: error: undefined label: label1706 if (getInventoryCount(new int[] { this.Vials }) != 0) if (getInventoryCo unt(new int[] { this.Identified }) != 0) { if (getInventoryCount(new int[] { thi s.Vials }) != 0) if (getInventoryCount(new int[] { this.Identified }) != 0) brea k label1706; if (getInventoryCount(new int[] { this.Unfinished }) != 0)

Scripts\OHDHerblaw.java:203: error: undefined label: label1706 break label1706; }

5 errors

내가 레이블을 정의하는 방법을 잘 모르겠어요 :

http://codepad.org/AB2gu59t

여기에 지금 얻을 오류입니다.

약간의 투쟁 끝에, 나는 그것을 작동 시켰습니다. 관심이있는 경우 수정 된 코드가 있습니다.

import java.io.BufferedReader; 
import java.io.DataInputStream; 
import java.io.FileInputStream; 
import java.io.InputStreamReader; 

public class OHDHerblaw extends Script { 

    int Herb; 
    int Identified = 0; 
    int Unfinished; 
    int Ingrediant; 
    int potsMade; 
    int Vials = 464; 
    int[] POTARRAY = new int[]{222, 474, 477, 480, 483, 486, 489, 492, 495, 498, 566, 569, 570}; 
    int[] UNIDARRAY = new int[0]; 
    int[] IDARRAY = new int[0]; 
    boolean onlyId = false; 
    boolean idHerbs = false; 
    boolean isMixing = false; 
    boolean unfinishedOnly = false; 


    public OHDHerblaw(Extension var1) { 
     super(var1); 
    } 

    public void init(String var1) { 
     String[] var2 = var1.trim().replaceAll(" ", "").split(","); 
     if(!var2[0].equals("")) { 
     this.Herb = Integer.parseInt(var2[0]); 
     if(this.Herb <= 443) { 
      if(this.Herb == 165 || this.Herb >= 435 && this.Herb <= 443) { 
       this.idHerbs = true; 
       this.unfinishedOnly = false; 
       if(this.Herb == 165) { 
        this.Identified = 444; 
        this.Unfinished = 454; 
       } else if(this.Herb > 165) { 
        this.Identified = this.Herb + 10; 
        this.Unfinished = this.Herb + 20; 
       } 
      } 
     } else if(this.Herb >= 444) { 
      if(this.Herb >= 444 && this.Herb <= 453) { 
       this.Herb -= 10; 
       this.Identified = this.Herb + 10; 
       this.Unfinished = this.Herb + 20; 
       this.idHerbs = false; 
       this.unfinishedOnly = false; 
      } else if(this.Herb >= 454 && this.Herb <= 463) { 
       this.Herb -= 20; 
       this.Identified = this.Herb + 10; 
       this.Unfinished = this.Herb + 20; 
       this.idHerbs = false; 
       this.unfinishedOnly = true; 
      } 
     } else { 
      System.out.println("That\'s is not a valid Herb Id..."); 
      this.stopScript(); 
     } 
     } 

     if(!var2[1].equals("")) { 
     this.Ingrediant = Integer.parseInt(var2[1]); 
     if(this.Ingrediant != 270 && this.Ingrediant != 473 && this.Ingrediant != 220 && this.Ingrediant != 219 && this.Ingrediant != 471 && this.Ingrediant != 469 && this.Ingrediant != 472 && this.Ingrediant != 501) { 
      System.out.println("No ingredient selected. We will not be making full potions..."); 
      this.Ingrediant = 0; 
      this.isMixing = false; 
     } else { 
      this.isMixing = true; 
     } 
     } 

     if(this.unfinishedOnly && !this.isMixing) { 
     System.out.println("Not possible, please re-check script setup..."); 
     this.stopScript(); 
     } 

    } 

    public int main() { 

     if(this.getFatigue() >= 90) { 
     this.useSleepingBag(); 
     return this.random(800, 1000); 
     } else { 
     if(!this.onlyId) { 
      int[] var1; 
      if(this.isMixing) { 
       if(this.idHerbs && this.getInventoryCount(new int[]{this.Herb}) > 0) { 
        this.useItem(this.getInventoryIndex(new int[]{this.Herb})); 
        return this.random(200, 350); 
       } 

       if(this.getInventoryCount(new int[]{this.Identified}) > 0 && this.getInventoryCount(new int[]{this.Vials}) > 0 && this.getInventoryCount(new int[]{this.Herb}) == 0) { 
        this.useItemWithItem(this.getInventoryIndex(new int[]{this.Identified}), this.getInventoryIndex(new int[]{this.Vials})); 
        return this.random(200, 350); 
       } 

       if(this.getInventoryCount(new int[]{this.Ingrediant}) > 0 && this.getInventoryCount(new int[]{this.Unfinished}) > 0) { 
        this.useItemWithItem(this.getInventoryIndex(new int[]{this.Ingrediant}), this.getInventoryIndex(new int[]{this.Unfinished})); 
        return this.random(500, 600); 
       } 

       if(this.getInventoryCount(new int[]{this.Herb}) == 0 && this.getInventoryCount(new int[]{this.Unfinished}) == 0 && this.getInventoryCount(new int[]{this.Identified}) == 0 || this.getInventoryCount(new int[]{this.Vials}) == 0 || this.getInventoryCount(new int[]{this.Identified}) == 0 || (this.getInventoryCount(new int[]{this.Vials}) == 0 || this.getInventoryCount(new int[]{this.Identified}) == 0) && this.getInventoryCount(new int[]{this.Unfinished}) == 0) { 
        if(this.isQuestMenu()) { 
        this.answer(0); 
        return this.random(2000, 3000); 
        } 

        if(this.isBanking()) { 
        int var2; 
        if(this.unfinishedOnly) { 
         if(this.getInventoryCount(new int[]{this.Ingrediant}) == 0 || this.getInventoryCount(new int[]{this.Unfinished}) == 0) { 
          for(var2 = 0; var2 < this.POTARRAY.length; ++var2) { 
           if(this.getInventoryCount(new int[]{this.POTARRAY[var2]}) > 0) { 
           this.deposit(this.POTARRAY[var2], this.getInventoryCount(new int[]{this.POTARRAY[var2]})); 
           return this.random(1250, 1500); 
           } 
          } 
         } 

         if(this.getInventoryCount(new int[]{this.Unfinished}) == 0) { 
          this.withdraw(this.Unfinished, 14); 
          return this.random(1500, 2000); 
         } 

         if(this.getInventoryCount(new int[]{this.Ingrediant}) == 0 && this.getInventoryCount(new int[]{this.Unfinished}) > 0) { 
          this.withdraw(this.Identified, this.getInventoryCount(new int[]{this.Unfinished})); 
          return this.random(1500, 2000); 
         } 

         this.closeBank(); 
         return this.random(200, 300); 
        } 

        if(!this.unfinishedOnly) { 
         if(this.getInventoryCount(new int[]{this.Ingrediant}) == 0 || this.getInventoryCount(new int[]{this.Unfinished}) == 0) { 
          for(var2 = 0; var2 < this.POTARRAY.length; ++var2) { 
           if(this.getInventoryCount(new int[]{this.POTARRAY[var2]}) > 0) { 
           this.deposit(this.POTARRAY[var2], this.getInventoryCount(new int[]{this.POTARRAY[var2]})); 
           return this.random(1250, 1500); 
           } 
          } 
         } 

         if(this.getInventoryCount(new int[]{this.Unfinished}) > 0) { 
          this.withdraw(this.Ingrediant, this.getInventoryCount(new int[]{this.Unfinished})); 
          this.closeBank(); 
          return this.random(2000, 3000); 
         } 

         if(this.getInventoryCount(new int[]{this.Vials}) == 0) { 
          this.withdraw(this.Vials, 14); 
          return this.random(1000, 1500); 
         } 

         if(this.getInventoryCount(new int[]{this.Herb}) == 0 && this.getInventoryCount(new int[]{this.Unfinished}) == 0 && this.getInventoryCount(new int[]{this.Identified}) == 0 && this.idHerbs) { 
          this.withdraw(this.Herb, 14); 
          return this.random(2000, 3000); 
         } 

         if(this.getInventoryCount(new int[]{this.Identified}) == 0) { 
          this.withdraw(this.Identified, 14); 
          return this.random(1000, 1500); 
         } 

         this.closeBank(); 
         return this.random(1000, 1500); 
        } 
        } 

        var1 = this.getNpcByIdNotTalk(this.BANKERS); 
        if(var1[0] != -1 && !this.isBanking() && !this.isQuestMenu() && this.getInventoryCount(new int[]{this.Ingrediant}) == 0) { 
        this.talkToNpc(var1[0]); 
        return this.random(3250, 3500); 
        } 
       } 
      } 

      if(!this.isMixing) { 
       if(this.idHerbs && this.getInventoryCount(new int[]{this.Herb}) > 0) { 
        this.useItem(this.getInventoryIndex(new int[]{this.Herb})); 
        return this.random(200, 350); 
       } 

       if(this.getInventoryCount(new int[]{this.Identified}) > 0 && this.getInventoryCount(new int[]{this.Vials}) > 0 && this.getInventoryCount(new int[]{this.Herb}) == 0) { 
        this.useItemWithItem(this.getInventoryIndex(new int[]{this.Identified}), this.getInventoryIndex(new int[]{this.Vials})); 
        return this.random(200, 350); 
       } 

       if(this.getInventoryCount(new int[]{this.Herb}) == 0 && this.getInventoryCount(new int[]{this.Unfinished}) == 0 && this.getInventoryCount(new int[]{this.Vials}) == 0 && this.getInventoryCount(new int[]{this.Identified}) == 0 || this.getInventoryCount(new int[]{this.Vials}) == 0 || this.getInventoryCount(new int[]{this.Identified}) == 0 || (this.getInventoryCount(new int[]{this.Vials}) == 0 || this.getInventoryCount(new int[]{this.Identified}) == 0) && this.getInventoryCount(new int[]{this.Unfinished}) == 0) { 
        if(this.isQuestMenu()) { 
        this.answer(0); 
        return this.random(2000, 3000); 
        } 

        if(this.isBanking()) { 
        if(this.getInventoryCount(new int[]{this.Herb}) == 0 && this.getInventoryCount(new int[]{this.Unfinished}) == 0 && this.getInventoryCount(new int[]{this.Vials}) == 0 && this.getInventoryCount(new int[]{this.Identified}) == 0 && this.idHerbs) { 
         this.withdraw(this.Herb, 14); 
         return this.random(2000, 3000); 
        } 

        if(this.getInventoryCount(new int[]{this.Unfinished}) > 0) { 
         this.deposit(this.Unfinished, this.getInventoryCount(new int[]{this.Unfinished})); 
         return this.random(200, 300); 
        } 

        if(this.getInventoryCount(new int[]{this.Vials}) == 0) { 
         this.withdraw(this.Vials, 14); 
         return this.random(1000, 1500); 
        } 

        if(this.getInventoryCount(new int[]{this.Identified}) == 0) { 
         this.withdraw(this.Identified, 14); 
         return this.random(1000, 1500); 
        } 

        this.closeBank(); 
        return this.random(1000, 1500); 
        } 

        var1 = this.getNpcByIdNotTalk(this.BANKERS); 
        if(var1[0] != -1 && !this.isBanking() && !this.isQuestMenu()) { 
        this.talkToNpc(var1[0]); 
        return this.random(3500, 3750); 
        } 
       } 
      } 
     } 

     return this.random(200, 300); 
     } 
    } 
} 
+2

무엇이 문제입니까? – Ingo

+0

한 단계를 해결 한 후에 전체 질문을 다시 작성하지 마십시오. 새 정보를 질문에 추가하거나 원래 질문과 크게 다른 경우 별도의 질문을하십시오. 그러나이 방법을 사용하면 나중에 솔루션을 검색하는 사람들에게 의미있는 질문을 남기지 않을 것입니다. (그리고 * 대부분은 SO 사용자입니다.) –

+0

여러 번 추가하려고 시도했지만 코드에 잘못된 들여 쓰기가 있었기 때문에 코드 패드에 넣은 것입니다. 코드와 관련하여, 필자와 다른 사람들도 이해할 수 있습니다. 라벨이 정의되어 있으면 왜 정의되지 않은 것으로 나타 납니까? –

답변

2

레이블은 used before a statement (JLS §14.7) 일 수 있습니다.

로컬 변수 선언은 구문이 아닙니다 (JLS-speak에서는 문장의 수퍼 세트) a "block statement" (JLS §14.2)입니다.

간단한은 전에 int[] arrayOfInt; 라인 에 레이블을 이동하고 당신이 잘되어야합니다 :

int i; 
label12: i = 42; // label on the assignment 

당신이 값을 할당하는 경우 : 할당에

int[] arrayOfInt; 
label417: 
if (this.isMixing) { 
    ... 
+0

원래 오류를 해결해 주신 Joachim에게 감사하지만 아직 정의되지 않은 레이블 오류가 발생했습니다. 당신이 제안한 것처럼 그것은 decompiled 코드입니다. –

+0

@ColiseSanders : 컴파일되지 않은 코드 컴파일에 대한 조언 :하지 마십시오. 첫째, 기술적 인 측면에서 볼 때 고통입니다. 둘째 : 보통은 허용되지 않습니다. –

0

라벨은 약간 다른 구문이 먼저 레이블을 정의해야합니다. 에 의해

if (!this.onlyId) 
    { 
     int[] arrayOfInt; 
     label417:  
     if (this.isMixing) 
     { 
     if (this.idHerbs) { 
      if (getInventoryCount(new int[] { this.Herb }) > 0) { 
      useItem(getInventoryIndex(new int[] { this.Herb })); 
      return random(200, 350); 
      } 
     } 
1

라벨이 따라야합니다 : 귀하의 경우

은에 코드를 변경합니다. 코드에서 변수 선언 다음에 선언문이 없습니다.

는 변수 선언 후 레이블을 이동

:

int[] arrayOfInt; 

label417: 
if (this.isMixing) { 
    // ... 

을 그건 그렇고, 내가 code smell 자바 코드에서 레이블을 사용 간주 - 코드의 설계에 문제가 있음을 나타냅니다 뭔가. 레이블은 goto statement과 같으며 코드를 이해하기 어렵게 만드는 악명 높은 구성입니다 (spaghetti code으로 연결됨).

레이블을 사용하는 대신 for 또는 while 루프와 같은 다른 제어 구조를 사용하십시오.

+0

나는이 코드가 일부 디 컴파일의 결과라고 확신한다. 라벨에는 "label417"이라는 레이블이 없습니다. –

+0

@JoachimSauer 사람들은 소스 코드에 레이블을 사용하면 안되지만 관계 없습니다. – Jesper

1

@ 요아킴의 답은 그것을 못 박았습니다.

난 그냥 이유를 설명 할

...

break <label> 문은 주어진 레이블이 현재의 방법에 둘러싸 문 밖으로 을 깰 수 있습니다. 지역 변수 선언에는 break 문을 포함 할 수 없습니다. 따라서 로컬 변수 선언에있는 label도 손상시킬 수 없습니다.

break <label> 문을 C/C++ goto 문과 같이 사용하려고 한 것으로 의심됩니다. 그런 식으로 작동하지 않습니다. 레이블이 허용 된 경우에도 해당 레이블에 침입 할 수 없습니다.예를 들어 이것은 똑같이 잘못되었습니다.

label: if (i == 1) { 
    // so something 
} 
if (i == 2) { 
    break label; // compilation error 
}