Nosuchelementexception

what’s wrong in this code…

import java.util.*;
public class Main {

static Scanner scn = new Scanner(System.in);

public static void main(String[] args) {
	Main m = new Main();
	int[] pre = takeInput();
	int[] in = takeInput();
	BinaryTree bt = m.new BinaryTree(pre, in);
	bt.display();
}

public static int[] takeInput() {
	int n = scn.nextInt();

	int[] rv = new int[n];
	for (int i = 0; i < rv.length; i++) {
		rv[i] = scn.nextInt();
	}

	return rv;
}

private class BinaryTree {
	private class Node {
		int data;
		Node left;
		Node right;
	}

	private Node root;
	private int size;
    int preoind;
	public BinaryTree(int[] pre, int[] in) {
		HashMap<Integer,Integer> h1=new HashMap<Integer,Integer>();
		preoind=0;
		for(int i=0;i<in.length;i++)
		{
			h1.put(in[i],i);
		}
		this.root = this.construct(pre,in,0,in.length-1,h1);
	}

	private Node construct(int[] pre,int in[],int str,int end,HashMap<Integer,Integer> h1) {
         if(str>end)
		 {
			 return null;
		 }
		 Node n1=new Node();
		 n1.data=pre[preoind++];
		 int inoind=h1.get(n1.data);
		 n1.left=construct(pre,in,str,inoind-1,h1);
		 n1.right=construct(pre,in,inoind+1,end,h1);
		 return n1;
		
	}

	public void display() {
		this.display(this.root);
	}

	private void display(Node node) {
		if (node == null) {
			return;
		}

		String str = "";

		if (node.left != null) {
			str += node.left.data;
		} else {
			str += "END";
		}

		str += " => " + node.data + " <= ";

		if (node.right != null) {
			str += node.right.data;
		} else {
			str += "END";
		}

		System.out.println(str);

		this.display(node.left);
		this.display(node.right);
	}

}

}

@Narasimha,
I have corrected your code https://ide.codingblocks.com/s/188608
There was a problem in the construct function also your hashmap is accessing an invalid index element. So I have removed the hashmap

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.