2012-10-09 62 views
0

我收到以下三個cannot find symbol錯誤,我不知道爲什麼!遇到「無法找到符號」的問題 - Java

GrammerQueue.java:9: cannot find symbol 
symbol : constructor GrammerStructure() 
location: class GrammerStructure 
public class GrammerQueue extends GrammerStructure implements StringQueue{ 
     ^
GrammerQueue.java:45: cannot find symbol 
symbol : variable stack 
location: class GrammerQueue 
      this.stack += tmpAr[i]; 
       ^
GrammerQueue.java:47: cannot find symbol 
symbol : variable count 
location: class GrammerQueue 
     this.count--; 
      ^
3 errors 

我得到了另一個腳本這個錯誤,通過調用類型的新對象,而不是直接調用我的類創建對象解決了它。但是,我甚至不想創建一個對象!我能做什麼?

下面的代碼:

import java.lang.*; 

public class GrammerQueue extends GrammerStructure implements StringQueue { 

    private String queue = ""; 
    private String structName; 

    // @override 
    public boolean offer(String item) { 
     if (item.length() == 0) // We don't accept empty Strings! 
      return false; 
     else if (this.queue.length() == 0) // If new queue, just add - no null. 
      queue = item; 
     else 
      // Append null and item for seperation. 
      queue += "\0" + item; 
     return true; // done. 
    } 

    // @override 
    public String[] asArray() { 
     // Splits the string at each null character and returns it as an array. 
     String[] array = this.queue.split("\0"); 
     return array; 
    } 

    // @override 
    public void GrammerStructure(String structureName) { 
     this.structName = structureName; 
    } 

    // @override 
    public String take() throws EmptyException { 
     // If empty, throw errors. 
     if (this.queue.length() == 0) 
      throw new EmptyException(structName); 
     String[] tmpAr = this.asArray(); 
     // Empties the stac now that we have it in a temp array. 
     this.queue = ""; 
     // FIFO, so exclude first element in reconstruction. 
     for (int i = 1; i < tmpAr.length; i++) 
      this.stack += tmpAr[i]; 
     // We made it this far without error, so reduce count. 
     this.count--; 
     // Return the first item. 
     return tmpAr[0]; 
    } 

    // @override 
    public String peek() { 
     // Empty string check. 
     if (this.queue.length() == 0) 
      return null; 
     String[] tmpAr = this.asArray(); 
     // Return the first item. 
     return tmpAr[0]; 
    } 

    // @override 
    public int size() { 
     if (this.queue.length() == 0) 
      return 0; 
     String[] tmpAr = this.asArray(); 
     return tmpAr.length; 
    } 

    // @override 
    public void clear() throws EmptyException { 
     // If empty, throw errors. 
     if (this.queue.length() == 0) 
      throw new EmptyException(structName); 
     else 
      this.queue = ""; // Empty now. 
    } 

    public void main(String args[]) {} 
} 

回答

3

看起來你沒有stackcount變量。您需要聲明和定義它們,並可能創建getter和setter。

假設GrammerStructure位於不同的包中,您需要爲GrammerStructure導入包。

+0

謝謝,我已經從另外一個這樣的代碼複製了一段代碼,錯過了,我完全忘記了我的構造函數! – user1695505

+0

現在工作嗎? –

+0

@ user1695505 ..如果這解決了你的問題..不要忘了標記這個答案爲可接受的。點擊箭頭旁邊的答案.. –

0

GrammerQueue擴展了GrammerStructure,它是一個不存在的類(AFAIK)。