i'm implementing a TreeSet, but when i try to add the second element i got NullPointerException and i can't figure out why:confused:. here is my class Month
Code:package navigableset;
public class Month implements Comparable<Month> {
private String name;
private String number;
public Month(int i, String name) {
this.number = number;
this.name = name;
}
public int compareTo(Month m) {
return this.number.compareTo(m.number);
}
}
and here is the class with the main() and where the error happen is when i try to add the object feb:
Code:package navigableset;
import java.util.NavigableSet;
import java.util.TreeSet;
public class TreeSetExample {
public static void main(String[] args) {
NavigableSet<Month> set = new TreeSet<Month>();
Month jan = new Month(1, "January");
Month feb = new Month(2, "February");
set.add(jan);
set.add(feb);
}
}

