Linked List Problem (83. Remove Duplicates from Sorted List)

Can anyone tell me why i am getting Object reference error in this line:
while(temp.next!=null)

Code:

   public ListNode DeleteDuplicates(ListNode head) {
        ListNode start=null;
        ListNode p=null;
        ListNode temp=head;
        int count=0;
        if(temp.next==null)
            return head;
        else if(head==null)
            return null;
        else
        {
            while(temp.next!=null)
        {
           if(temp.val!=temp.next.val)
           {
               if(start==null)
               {
                   start=temp;
                   if(count==0)
                   {
                       head=start;
                       count+=1;
                   }
               }
               else
               {
                   p=temp;
                   start.next=p;
                   start=p;
               }
               
           }
            temp=temp.next;
        }
        p.next=temp;
        return head;
        }       
    }
Comments (1)