Heap merge k sorted array

why it give run time error ? how to debug it.
import java.util.*;
public class HeapGeneric< T extends Comparable> {

ArrayList data=new ArrayList<>();

public void add(T item)
{
data.add(item);
upheapify(this.data.size()-1);
}

public T remove()
{
swap(0,this.data.size()-1);
T rv=this.data.remove(this.data.size()-1);
downheapify(0);
return rv;
}

private void downheapify(int pi)
   {
    int lc=2*pi+1;
	int rc=2*pi+2;
    int mini=pi;

    if(lc < this.data.size() && isLarger(data.get(lc),data.get(mini)) >0)
	    mini=pi;

	 if(rc <data.size()  && isLarger(data.get(rc),data.get(mini)) >0)
	   mini=pi;
   
     if(mini!=pi)
	  {
		swap(mini,pi);
		downheapify(mini);
	  }
   }

  private void upheapify(int c)
     {
       int pi=(c-1)/2;

	   if(isLarger(data.get(c),data.get(pi)) > 0)
	      {
            swap(pi,c);
           upheapify(pi);
		  }
	 } 
 
  private void swap(int i,int j)
     {
		T ith=data.get(i);
		T jth=data.get(j);

		data.set(i,jth);
		data.set(j,ith);
	 }
  public int isLarger(T t,T o)
    {
	  return t.compareTo(o);
	} 

class Pair implements Comparable {
int data;
int listNo;
int idxNo;

    public int compareTo(Pair o) {
        return o.data - this.data;
    }

}

private boolean isEmpty()
{
return this.data.size()==0;
}
public static void merge(ArrayList<ArrayList> list)
{
HeapGeneric heap=new HeapGeneric<>();

	   for(int i=0;i<list.size();i++)
	     {
            Pair np=new Pair();
			np.data=list.get(i).get(0);
            np.idxno=0;
			np.listno=i;
		 heap.add(np);
		 }

		while(!heap.isEmpty())
		  {
            Pair rp=heap.remove();
			System.out.println(rp.data);
			rp.idxno++;

		    if(rp.idxno < list.get(rp.listno).size())
		      {
                 rp.data = list.get(rp.listno).get(rp.idxno);
               heap.add(rp);  
			  }	
		  } 

   }
public static void main(String args[]) {
 Scanner kb=new Scanner(System.in);
 int n=kb.nextInt();
 int k=kb.nextInt();

 ArrayList<ArrayList<Integer>> list=new ArrayList<>(k);
 while(k-->0)
    {
      ArrayList<Integer> list1=new ArrayList<>();
	   for(int i=0;i<n;i++)
		{	int a=kb.nextInt();
			list1.add(a);
		}
	 list.add(list1);	
	}
  
   HeapGeneric<Pair> heap=new HeapGeneric<>();
   heap.merge(list);
   
}

}

there were problems in

handling generic type T
downheapify()
input order, first k then n

I updated the code and it can be found in https://ide.codingblocks.com/s/207146

thanks

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.