找不到符号方法 getNext()?

发布于 2024-12-25 13:25:14 字数 2041 浏览 0 评论 0原文

我正在运行 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()。

该代码之前运行良好,但最近我的编译器冻结并且没有响应,因此我通过任务管理器结束了该过程。从那时起,它就开始发挥作用了。

谁能解释为什么它不起作用?我认为这不是我的问题,而是编译器的问题。

I am running BlueJ as my IDE. For some odd reason I get an error in this line of code:

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());
    } 


}

The error is: Cannot find symbol- method getNext().

The code was working perfectly before but recently my compiler froze and was not responding so I ended the process via Task Manager. Since then it started to act up.

Can anyone explain why it is not working? I don't think that it is my issue, but rather the compilers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘虞初梦 2025-01-01 13:25:14

可能的情况是:

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

我无法确定是哪一行代码导致的,因为您没有为 Node 类提供代码。但是,仔细检查 Node 类并确保两个 getNext() 都存在,并且您按照预期的方式调用它(传递有效参数,等等)。

The likely cases are either:

  • The method getNext() does not exist within the Node class, or
  • the calling signature of getNext() doesn't match with how it's defined (despite it being an accessor).

I can't say for certain which line of code is causing it, as you haven't provided code for the Node class. However, comb through the Node class and make certain that both getNext() exists, and you're calling it the way you're supposed to (passing valid arguments, and so forth).

梦初启 2025-01-01 13:25:14

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

Check the xml files. I had the same problem. I was calling a TextView that I previously rename and forgot to change the name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文