Delete nodes from BST program error

I wrote this code for this challenge and I am getting an error and I dont know why.

import java.util.Scanner;
public class Main {
static Scanner scn = new Scanner(System.in);
public static void main(String args[]) {
Main obj = new Main();
int t = scn.nextInt();
while(t>0){
int n = scn.nextInt();
int[] A1 = new int[n];
takeinput(A1);
int m = scn.nextInt();
int[] A2 = new int[m];
takeinput(A2);
BinarySearchTree tree = obj.new BinarySearchTree(A1);
for(int i=0;i<A2.length;i++)
tree.remove(A2[i]);
tree.preorder();
System.out.println();
t–;
}
}
public static void takeinput(int[] arr){
for(int i=0;i<arr.length;i++)
arr[i] = scn.nextInt();
}
class BinarySearchTree{
private class Node{
int data;
Node left;
Node right;
}
private Node root;
private int size;
BinarySearchTree(int[] arr){
for(int i=0;i<arr.length-1;i++)
this.root = takeInput(arr[i],root);
}
public Node takeInput(int val,Node root){
if(root==null){
Node nn = new Node();
nn.data=val;
return nn;
}
if(val<root.data){
root.left=takeInput(val,root.left);
}else if(val>root.data){
root.right=takeInput(val,root.right);
}
return root;
}
public void remove(int item){
remove(this.root,null,false,item);
}
private void remove(Node node,Node parent,boolean ilc,int item){
if(node==null){
return;
}
if(item>node.data){
remove(node.right,node,false,item);
}else if(item<node.data){
remove(node.left,node,true,item);
}else{
if(node.left==null&&node.right==null){
if(ilc){
parent.left=null;
}else{
parent.right=null;
}
}else if(node.left!=null&&node.right==null){
if(ilc){
parent.left=node.left;
}else{
parent.right=node.left;
}
}else if(node.left==null&&node.right!=null){
if(ilc){
parent.left=node.right;
}else{
parent.right=node.right;
}
}else{
int min = min(node.right);
node.data=min;
remove(node.right,node,false,min);
}
}
}
public int min(){
return min(this.root);
}
public int min(Node node){
if(node.left==null){
return node.data;
}
return min(node.left);
}
public void preorder(){
preorder(this.root);
}
private void preorder(Node node){
if(node==null){
return;
}
System.out.print(node.data+" ");
preorder(node.left);
preorder(node.right);
}
}
}

@sanchit02,
https://ide.codingblocks.com/s/231680 corrected code. You missed on test cases if parent is null. I have added comments on the lines I have added for your reference.

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.