A
aa
Hi, I'm a beginner programmer and I keep getting stuck on this one
problem:
I try to make a new node:
TreeNode newTree = new TreeNode(someitem(),somechild());
but, I keep getting null pointer exceptions on this line:
Child.setItem(kids.head.listItem);
does that mean that either Child or kids.head.listItem doesnt exist?
public class TreeNode {
private Object item;
private TreeNode Child;
private TreeNode Sibling;
public TreeNode(Object item, SList kids) {
this.item = item;
Child.setItem(kids.head.listItem); // this one
}
public class SList {
public SListNode head;
public SList() {
head = null;
}
public SList(SListNode head) {
this.head = head;
}
public class SListNode {
public Object listItem;
public SListNode next;
public SListNode(Object item) {
this.listItem = item;
}
problem:
I try to make a new node:
TreeNode newTree = new TreeNode(someitem(),somechild());
but, I keep getting null pointer exceptions on this line:
Child.setItem(kids.head.listItem);
does that mean that either Child or kids.head.listItem doesnt exist?
public class TreeNode {
private Object item;
private TreeNode Child;
private TreeNode Sibling;
public TreeNode(Object item, SList kids) {
this.item = item;
Child.setItem(kids.head.listItem); // this one
}
public class SList {
public SListNode head;
public SList() {
head = null;
}
public SList(SListNode head) {
this.head = head;
}
public class SListNode {
public Object listItem;
public SListNode next;
public SListNode(Object item) {
this.listItem = item;
}