Why runtime error is coming pls help me

import java.util.Scanner;

public class Main {

private Node head;
private Node tail;
private int size;

private class Node {
	int data;
	Node next;

	Node(int data, Node next) {
		this.data = data;
		this.next = next;
	}
}

public Main() {
	this.head = this.tail = null;
	this.size = 0;
}

public int size() {
	return this.size;
}

public void addLast(int data) {
	Node node = new Node(data, null);

	if (this.size() == 0) {
		this.head = this.tail = node;
	} else {
		this.tail.next = node;
		this.tail = node;
	}
	this.size++;
}

public void display() {
	Node temp = this.head;
	while (temp != null) {
		System.out.print(temp.data + " ");
		temp = temp.next;
	}
}

private Node getNode(int idx) throws Exception {
	if (idx < 0 || idx >= this.size) {
		throw new Exception("Invalid Index");
	}
	if (this.size == 0) {
		throw new Exception("Linked List is empty");
	}
	Node tempNode = head;
	for (int i = 1; i <= idx; i++) {
		tempNode = tempNode.next;
	}
	return tempNode;
}

public Node kthNodeFromLast(int k) {
	Node slow = this.head;
	Node fast = this.head;
	for (int i = 0; i < k; i++) {
		fast = fast.next;
	}

	while (fast != null) {
		fast = fast.next;
		slow = slow.next;

	}
	return slow;
}

public void appendToFront(int n) throws Exception {

	// getting n+1th node
	Node nth = kthNodeFromLast(n+1); // 6 
    Node np1 = nth.next;
    
	nth.next = null;
	this.tail.next = this.head;
    this.head = np1;
    
	 
}

public static void main(String[] args) throws Exception {
	Scanner scanner = new Scanner(System.in);
	Main list = new Main();
	int S = scanner.nextInt();

	for (int i = 0; i < S; i++) {
		list.addLast(scanner.nextInt());
	}
	int k = scanner.nextInt();
	list.appendToFront(k);

	 list.display();

}

}

hey, do n = n % length for cases where n > length

refer to this