public abstract class destination{
//Here are the data that are common in each of the 'File Types'
protected tree root;
//constructor that will call the correct constructor when a derived children is made.
public destination()
{
super(); //Will call the other constructors
}
public void get_info()
{
}
public void print()
{
}
public void add_comment(String comment)
{
root.add_comments(root, comment); //null pointer exception
}
}
我来自 C++,所以我以前从未遇到过这个问题。通常要访问一个函数,我可以像 root->add_comment(root, comment); 它会工作得很好,但是在java中它给了我一个空指针,我必须初始化root吗?因为在树类中我有一个 add_comment 函数,它递归地将一个节点添加到树中。