找不到符号方法 getNext()?
我正在运行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能的情况是:
getNext()
,或者getNext()
的调用签名与其定义方式不匹配(尽管它是一个访问器)。我无法确定是哪一行代码导致的,因为您没有为 Node 类提供代码。但是,仔细检查 Node 类并确保两个
getNext()
都存在,并且您按照预期的方式调用它(传递有效参数,等等)。The likely cases are either:
getNext()
does not exist within the Node class, orgetNext()
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).检查 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.