2015-06-29 186 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类的前面加上公共关键字。编译并再次运行它。我认为它会起作用。

相关问题