找不到符号方法getNext()?

时间:2012-01-09 22:22:56

标签: java compiler-errors

我正在运行BlueJ作为我的IDE。由于某些奇怪的原因,我在这行代码中遇到错误:

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()。

代码在之前工作得很好,但最近我的编译器冻结了,没有响应,所以我通过任务管理器结束了这个过程。从那以后它开始起作用。

任何人都可以解释为什么它不起作用?我不认为这是我的问题,而是编译器。

2 个答案:

答案 0 :(得分:0)

可能的情况是:

  • 方法getNext()在Node类中不存在,或
  • getNext()的调用签名与其定义方式不匹配(尽管它是一个访问者)。

我无法确定哪一行代码导致它,因为您没有为Node类提供代码。但是,梳理Node类并确保两个getNext()都存在,并且您以您应该的方式调用它(传递有效参数,等等)。

答案 1 :(得分:0)

检查 xml 文件。我有同样的问题。我正在调用之前重命名的 TextView,但忘记更改名称。