-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()。
代码工作完美之前,但最近我的编译器冻结,没有响应,所以我通过任务管理器结束了过程。从那时起它开始行动起来。
任何人都可以解释为什么它不工作?我不认为这是我的问题,而是编译器。
多一点上下文会有所帮助 - 什么样的对象类型是'temp'?它的方法是什么,[因此]它们的签名是什么? – Makoto 2012-01-09 22:24:36
'temp'的类型(class)是什么?它是你自己的类还是某个系统类?你确定它有一个'getNext()'方法吗? – 2012-01-09 22:24:51
什么是温度?请发布更多的while循环之前的代码。 – kosa 2012-01-09 22:24:52