I don't understand why all the data gets printed in the arrange method correctly but does not get printed in the print method. : In tree class there is a method called arrange().When i print any node value within the arrange ()method the value comes to be accurate but when i use the method print() in tree class i get a null pointer exception, please help!!


        
    public class Node {
	Node lnode;
	Node rnode;
	int data;
	public Node(String d)
	{
		data=Integer.parseInt(d);
		this.rnode=null;
		this.lnode=null;
	}
    }
    public class tree {

	public void arrange(String s[],int n,Node r)
	{ 
			Node root=new Node(s[0]);
	for(int i=1;i<n;i++)
		{
		r=root;
		 if(Integer.parseInt(s[i])>root.data&&root.rnode==null)
		 {
			 root.rnode=new Node(s[i]);
		 }
		 else if(Integer.parseInt(s[i])<root.data&&root.lnode==null)
			 root.lnode=new Node(s[i]);

			while(!(r.rnode==null)&&(Integer.parseInt(s[i]))>r.data)
		{
			
			r=r.rnode;
		if(Integer.parseInt(s[i])>r.data&&r.rnode==null)
			r.rnode=new Node(s[i]);
		else if(Integer.parseInt(s[i])<r.data&&r.lnode==null)
		 r.lnode=new Node(s[i]);
		}
		while(!(r.lnode==null)&&(Integer.parseInt(s[i]))<r.data)
			{
			r=r.lnode;
		if(Integer.parseInt(s[i])>r.data&&r.rnode==null)
			r.rnode=new Node(s[i]);
		else if(Integer.parseInt(s[i])<r.data&&r.lnode==null)
		 r.lnode=new Node(s[i]);
		
			}
	}
	**System.out.println(root.rnode.data);**
	}
	public void print(Node r)
	{
		System.out.println(r.rnode.data);	
	}
   }