Results 1 to 3 of 3

Thread: NullPointerException thrown?

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Resolved NullPointerException thrown?

    Im trying to have an Object implement a custom Comparable but the single compareTo(T o) method found in the Comparable interface has to stay like it is. ie Having an object as a parameter. So i added in the cast to the type which is being held in the Collection and thus being sorted upon. The line i added It sounds correct since a ClassCastException should never be thrown since the Collection is marked to hold only employee objects. Any ideas? Thanks.
    Code:
    public int compareTo(Object o){
     Employee e = (Employee)o; // added line 
     int i = lname.compareTo(e.lname);      
     return (i != 0 ? i : fname.compareTo(e.fname));  
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width