2012-01-09 90 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()都存在,并且按照您应该的方式调用它(传递有效参数,等等)。