I'm writing a method to remove duplicate Node, but it keeps getting NullPointerException at line: while (m.next != null).
public class Node {
    public int data;
    public Node next;
    public Node (int data) {
        this.data = data;
        this.next = null;
    }
    public void removeDup () {
        Node n = this;
        while (n != null) {
            Node m = n;
            while (m.next != null) {
                if (n.data == m.next.data) 
                    m.next = m.next.next;
                m = m.next;
            }
            n = n.next;
        }
    }
}
 
     
     
    