2012-01-09 93 views
-1

我正在運行BlueJ作爲我的IDE。由於某種奇怪的原因,我在此行代碼中出現錯誤:找不到符號方法getNext()?

import javax.swing.*; 

public class RotateArrayCircularLL 
{ 
    private Node head=null; 

    // ================================================================================== 
    public void init() 
    { 

     int choice = 0; 

     while (choice != -1){ 
     choice = Integer.parseInt(JOptionPane.showInputDialog("Enter -1 to stop loop, 1 to continue"));  

     if(choice == -1) 
      break; 

     inputNum(); 

     } 
     printList(); 
    } 

    public void inputNum() 
    { 
     Node n; 
     Node temp; 
     int k; 

     k = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter a number:")); 
     n = new Node(k);  

     if (head == null) { 
      head = n;    
     } else {    
      temp = head; 
      while (temp.getNext() != null) 
       temp = temp.getNext(); 

      temp.setNext(n);     
     }  

    } 


    public void printList() 
    { 
     Node temp = head; 
     Node d, e; 

     int count = Integer.parseInt(JOptionPane.showInputDialog("Enter the value to shift to the right")); 

     for (int i = 1; i <= count; i++) // Rotates the head 
      temp = temp.getNext(); 

     for (e = head; e != null; e = e.getNext()){ 
      if (e.getNext() != null) 
      System.out.print(e.getInfo() + "-"); 
      if (e.getNext() == null) 
      System.out.print(e.getInfo()); 
     } 

     for (Node c = temp; c != null && c.getNext() != head; c= c.getNext()){ 
       System.out.print(c.getInfo() + "-"); 
     } 
     for (d = head; d != null && d.getNext() != temp; d = d.getNext()) 
     { 
      System.out.print(d.getInfo()+ "-"); 
     } 
     System.out.println(d.getInfo()); 
    } 


} 

錯誤是:找不到符號方法getNext()。

代碼工作完美之前,但最近我的編譯器凍結,沒有響應,所以我通過任務管理器結束了過程。從那時起它開始行動起來。

任何人都可以解釋爲什麼它不工作?我不認爲這是我的問題,而是編譯器。

+0

多一點上下文會有所幫助 - 什麼樣的對象類型是'temp'?它的方法是什麼,[因此]它們的簽名是什麼? – Makoto 2012-01-09 22:24:36

+0

'temp'的類型(class)是什麼?它是你自己的類還是某個系統類?你確定它有一個'getNext()'方法嗎? – 2012-01-09 22:24:51

+0

什麼是溫度?請發佈更多的while循環之前的代碼。 – kosa 2012-01-09 22:24:52

回答

0

的可能的情況下,要麼是:

  • getNext()不Node類中存在,或
  • getNext()調用簽名不與它是如何定義的(符合儘管它是一個訪問的方法)。

我不能說某些代碼行導致它,因爲你沒有提供Node類的代碼。但是,梳理Node類並確保兩個getNext()都存在,並且按照您應該的方式調用它(傳遞有效參數,等等)。