It is showing run time error

import java.util.*;
class LinkedList {

static Node head1, head2; 

static class Node { 

    int data; 
    Node next; 

    Node(int d) 
    { 
        data = d; 
        next = null; 
    } 
} 

/*function to get the intersection point of two linked 
lists head1 and head2 */
int getNode() 
{ 
    int c1 = getCount(head1); 
    int c2 = getCount(head2); 
    int d; 

    if (c1 > c2) { 
        d = c1 - c2; 
        return _getIntesectionNode(d, head1, head2); 
    } 
    else { 
        d = c2 - c1; 
        return _getIntesectionNode(d, head2, head1); 
    } 
} 

/* function to get the intersection point of two linked 
 lists head1 and head2 where head1 has d more nodes than 
 head2 */
int _getIntesectionNode(int d, Node node1, Node node2) 
{ 
    int i; 
    Node current1 = node1; 
    Node current2 = node2; 
    for (i = 0; i < d; i++) { 
        if (current1 == null) { 
            return -1; 
        } 
        current1 = current1.next; 
    } 
    while (current1 != null && current2 != null) { 
        if (current1.data == current2.data) { 
            return current1.data; 
        } 
        current1 = current1.next; 
        current2 = current2.next; 
    } 

    return -1; 
} 

/*Takes head pointer of the linked list and 
returns the count of nodes in the list */
int getCount(Node node) 
{ 
    Node current = node; 
    int count = 0; 

    while (current != null) { 
        count++; 
        current = current.next; 
    } 

    return count; 
} 
public static void main(String args[]) {
	Scanner sc = new Scanner(System.in);
	int n1 = sc.nextInt();
	LinkedList list = new LinkedList();
	list.head1.data = sc.nextInt();
	for(int i = 1;i<n1;i++){
		list.head1.next.data = sc.nextInt();
	}
	int n2 = sc.nextInt();
	list.head2.data = sc.nextInt();
	for(int i = 1;i<n2;i++){
		list.head2.next.data = sc.nextInt();
	}
	System.out.println(list.getNode());

}

}

your head1 and head2 are null only first you have to create new nodes and assign values to them
you cannot access properties of null object.so whenever you want to add value to next node create Node using constructor first.

please provide me the corrections and the corrected code of my program

yeah sure @8006366388

import java.util.*;
class LinkedList {

static Node head1, head2;

static class Node {

int data; 
Node next; 

Node(int d) 
{ 
    data = d; 
    next = null; 
} 

}

/*function to get the intersection point of two linked
lists head1 and head2 */
int getNode()
{
int c1 = getCount(head1);
int c2 = getCount(head2);
int d;

if (c1 > c2) { 
    d = c1 - c2; 
    return _getIntesectionNode(d, head1, head2); 
} 
else { 
    d = c2 - c1; 
    return _getIntesectionNode(d, head2, head1); 
} 

}

/* function to get the intersection point of two linked
lists head1 and head2 where head1 has d more nodes than
head2 */
int _getIntesectionNode(int d, Node node1, Node node2)
{
int i;
Node current1 = node1;
Node current2 = node2;
for (i = 0; i < d; i++) {
if (current1 == null) {
return -1;
}
current1 = current1.next;
}
while (current1 != null && current2 != null) {
if (current1.data == current2.data) {
return current1.data;
}
current1 = current1.next;
current2 = current2.next;
}

return -1; 

}

/*Takes head pointer of the linked list and
returns the count of nodes in the list */
int getCount(Node node)
{
Node current = node;
int count = 0;

while (current != null) { 
    count++; 
    current = current.next; 
} 

return count; 

}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n1 = sc.nextInt();
LinkedList list = new LinkedList();
Node h1 = new Node(sc.nextInt());
list.head1=h1;
for(int i = 1;i<n1;i++){
h1.next = new Node(sc.nextInt());
h1=h1.next;
}

int n2 = sc.nextInt();
Node h2 = new Node(sc.nextInt());
list.head2=h2;
for(int i = 1;i<n2;i++){
	h2.next = new Node(sc.nextInt());
	h2=h2.next;
}
System.out.println(list.getNode());

}
}

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.

still error is showing in ur code at line 26,30 and 89 please remove this error i am not able to understand error

@8006366388
hey buddy its submitted code .
send me your mail
i will email you the code the again.

[email protected]

it is showing error in ur if condition and for condition

@8006366388
check your mail akshay if you still face any doubt you can inbox me

@8006366388
please mark your doubt as resolved if you are satisfied with the solution.

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.