I just need some help figuring why I'm getting a NullPointerException where the "height" starts under the insert method. I posted the whole code before but some editing errors happened and if you wanna see the whole code again I can paste that in again but I just need help specifically on this.

I'm just getting an error beginning at "if(t.left().height() - t.right().height() == 2){"

Am I using this the wrong way? I feel like the way i'm coding that part to find the height of the left tree is incorrect.

[/COLOR]//constructor public static class AvlTreeNode{ private int value; private AvlTreeNode left; private AvlTreeNode right; private int height; public AvlTreeNode(int value, AvlTreeNode left, AvlTreeNode right){ this.value = value; this.left = null; this.right = null; height = 0; } public AvlTreeNode(int value){ this.value = value; left = null; right = null; } public AvlTreeNode left(){ return this.left; } public AvlTreeNode right(){ return this.right; } public int value(){ return this.value; } public int height(){ return this.height; } } //method to insert a new node and number to a tree public static AvlTreeNode insert(AvlTreeNode t, int x){ if(t == null){ t = new AvlTreeNode(x,null,null); return t; }else if(x < t.value()){ t.left = insert(t.left(), x); }else if(x > t.value()){ t.right = insert(t.right(), x); } if(t.left().height() - t.right().height() == 2){ if(x < t.left.value()){ t = singleRotateWithLeft(t); } else if(x > t.left().value()){ t = doubleRotateWithLeft(t); } else if(x > t.value()){ t.right = insert(t.right(), x); } } return t; }