正在学习 LinkedList 和 Nodes,但我在 buildList 方法中的 newNode 上不断收到 "cannot be resolved or is not in field" 错误
Learning LinkedList and Nodes, but I keep getting a "cannot be resolved or is not in field" error on newNode in buildList method
几天来我一直在努力解决这个问题,但我所做的一切都是错误的。
我在 buildList 方法的 newNode.next 上不断收到 .next 的 "cannot be resolved or is not in field" 错误。
对于 printList 方法中 current.next/ current.data 上的 .next 和 .data,我也遇到了同样的错误。
我拥有的是书中的内容,但它不想在 Eclipse 中工作。
请帮忙...
package linkedList;
import java.util.*;
import org.w3c.dom.Node;
public class ListOne {
//This part needs various options:
//Build list
//clear list
//check if the list is sorted
//insert at head
static Scanner input = new Scanner(System.in);
public static Node head;
public int linkedListCount = 0;
//public static LinkedList<Integer> intList = new LinkedList<Integer>();
private class MyNode{
private int data;
private Node next;
public MyNode(int data){
this.data = data;
this.next = null;
}
}
//BUILD LIST
public void buildList(int value){
Node newNode = (Node) new MyNode(value);
newNode.next = head;
head = newNode;
}
//Clear the list
public void clearList(){
head = null;
}
public void printList () {
if(head == null){
return;
}
Node current = head;
while (current != null) {
// visit
System.out.println(current.data);
current = current.next;
} // traversal
} // printList
public boolean isEmpty(){
return head == null;
}
}
Here is the errors I am receiving.
In method buildList, on newNode.next = "next cannot be resolved or is not a field." / In method printList, on current.data = "data cannot be resolved or is not a field." / In method printList, on current.next = "next cannot be resolved or is not a field."
我完全看不出使用 Node
界面有任何意义。始终使用 MyNode
:
package linkedList;
import java.util.*;
//import org.w3c.dom.Node; No need for this
public class ListOne {
// .....
public static MyNode head;
private class MyNode{
private int data;
private MyNode next;
public MyNode(int data){
this.data = data;
this.next = null;
}
}
//BUILD LIST
public void buildList(int value){
MyNode newNode = new MyNode(value);
newNode.next = head;
head = newNode;
}
// etc....
}
几天来我一直在努力解决这个问题,但我所做的一切都是错误的。 我在 buildList 方法的 newNode.next 上不断收到 .next 的 "cannot be resolved or is not in field" 错误。 对于 printList 方法中 current.next/ current.data 上的 .next 和 .data,我也遇到了同样的错误。 我拥有的是书中的内容,但它不想在 Eclipse 中工作。 请帮忙...
package linkedList;
import java.util.*;
import org.w3c.dom.Node;
public class ListOne {
//This part needs various options:
//Build list
//clear list
//check if the list is sorted
//insert at head
static Scanner input = new Scanner(System.in);
public static Node head;
public int linkedListCount = 0;
//public static LinkedList<Integer> intList = new LinkedList<Integer>();
private class MyNode{
private int data;
private Node next;
public MyNode(int data){
this.data = data;
this.next = null;
}
}
//BUILD LIST
public void buildList(int value){
Node newNode = (Node) new MyNode(value);
newNode.next = head;
head = newNode;
}
//Clear the list
public void clearList(){
head = null;
}
public void printList () {
if(head == null){
return;
}
Node current = head;
while (current != null) {
// visit
System.out.println(current.data);
current = current.next;
} // traversal
} // printList
public boolean isEmpty(){
return head == null;
}
}
Here is the errors I am receiving. In method buildList, on newNode.next = "next cannot be resolved or is not a field." / In method printList, on current.data = "data cannot be resolved or is not a field." / In method printList, on current.next = "next cannot be resolved or is not a field."
我完全看不出使用 Node
界面有任何意义。始终使用 MyNode
:
package linkedList;
import java.util.*;
//import org.w3c.dom.Node; No need for this
public class ListOne {
// .....
public static MyNode head;
private class MyNode{
private int data;
private MyNode next;
public MyNode(int data){
this.data = data;
this.next = null;
}
}
//BUILD LIST
public void buildList(int value){
MyNode newNode = new MyNode(value);
newNode.next = head;
head = newNode;
}
// etc....
}