我需要创建一个树数组并获取用户输入的字母并将其放入节点中。我收到与 forest[i].root 相关的 NullPointerException 错误。我怎样才能解决这个问题?
class TreeApp
{
public static void main(String[] args) throws IOException
{
Tree forest[] = new Tree[10];
Scanner kb = new Scanner(System.in);
for(int i = 0; i < 10; i++)
{
System.out.println("Insert a letter: ");
Node newNode = new Node();
newNode.iData = kb.next().charAt(0);
System.out.println("node: " + newNode.iData );
forest[i].root = newNode;
}
}
}