Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

null pointer exception while using compareTo()

843829Sep 26 2005 — edited Sep 26 2005
plz help!~
public class Student implements Comparable
{
	private long studentId;
	private String studentName;
	private String surname;

public int compareTo(Object other)
	{
	int order = 0;
	{
	if (surname.equals(((Student)other).surname))	
	order = studentName.compareTo(((Student)other).studentName);
                      else
	order = surname.compareTo(((Student)other).surname);
	return order;
	}
this is my code, when i run the program, i got a NullPointerException in this line : order = surname.compareTo(((Student)other).surname);

what's wrong?? what is it that is null? The surname? or the student object??
plz help me~~ really frustrated to see my assignment becomes like this...i always start early but still end up in this situation...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 24 2005
Added on Sep 26 2005
4 comments
665 views