2015-06-29 183 views
-2

當我啓動時,它給了我這個錯誤,類名是AQueueClass 任何幫助?錯誤:無法找到或加載主

package `com.thekyle.hi;` 

    class QDemo { 
     // a queue class for characters 
     char q[]; // this array holds the queue 
     int putloc, getloc; // the put and get indices 

     QDemo(int size) { 
      q = new char[size + 1]; 
      putloc = getloc = 0; 

     }// put a character into the queue 

     void put(char ch) { 
      if (putloc == q.length - 1) { 
       System.out.println(" - Queue is full silly- "); 
       return; 
      } 

      putloc++; 
      q[putloc] = ch; 

     } 

     char get() {// gets a character from the queue 
      if (getloc == putloc) { 
       System.out.println(" Queue is empty"); 
       return (char) 0; 
      } 
      getloc++; 
      return q[getloc]; 
     } 
    } 
      class AQueueClass { 
      public static void main(String args[]) {   
       QDemo bigQ = new QDemo(100); 
       QDemo smallQ = new QDemo(4); 
       char ch; 
       int i; 
       System.out.println("Using bigQ to store the alphabet"); 
       for (i = 0; i < 26; i++) { 
        bigQ.put((char) ('A' + i)); 
        // retrieve and display elements from bigQ 
        System.out.println("Contents of bigQ: "); 
        for (i = 0; i < 26; i++) { 
         ch = bigQ.get(); 
         if (ch != (char) 0) 
          System.out.print(ch); 

        } 
        System.out.println("\n"); 
        System.out.println("Using small q to generate errors"); 
        for (i = 0; i < 5; i++) { 
         System.out.print("Attemting to store " + (char) ('Z' - i)); 
         smallQ.put((char)('Z' - i)); 
         System.out.println(); 

        } 
        System.out.println(); 
        System.out.println("Contents of smallQ: "); 
        for (i = 0; i < 5; i++) { 
         ch = smallQ.get(); 
         if(ch != (char) 0) System.out.print(ch); 
        } 


       } 

      } 
     } 

如果它的類路徑問題,我在哪裏可以找到類路徑?既然它說我需要更多的細節,所以這裏有一些填充。

+2

「既然它說我需要更多細節」。你最好添加一些,而不是無用的填充物。就像完整的錯誤信息或者你如何嘗試開始你的課程一樣......並且真的是你的包裝聲明中的那些滴答聲? – Marvin

+0

錯誤:無法找到或加載主類com.thekyle.hi.AQueueClass $ BigE –

回答

0

你用什麼名字保存你的java文件。如果你的java文件中有兩個類,那麼嘗試讓你的類包含main()方法作爲公共類。

+0

我將本書中的代碼跟在單詞旁邊,所以它可能是一個類路徑問題。但我不知道那是哪裏。 –

+0

謝謝,你解決了它,但一個新的錯誤出現了,我必須等3天才能問。 –

0

嘗試通過名稱AQueueClass來保存文件,然後也AQueueClass類的前面加上公共關鍵字。編譯並再次運行它。我認爲它會起作用。

相關問題