The problem arises in the merge function at 'while(m.next!=null)'. It throws a "NullPointerException".
public class Linked {
node ptr1;
node ptr2;
void merge()
{
node m=ptr1;
while(m.next!=null)
m=m.next;
m.next=ptr2;
}
void printmerged()
{
node m=ptr1;
while(m.next!=null)
System.out.print(m.data+", ");
System.out.println(m);
}
}