I have the following code, which seems very simple and straight-forward:
public static void main(String[] args) {
Series<String, Number> series = new Series<String, Number>();
ObservableList<Data<String, Number>> list = series.getData();
list.add(new Data<String,Number>("1", new Double(1)));
list.add(new Data<String,Number>("2", new Double(2)));
list.add(new Data<String,Number>("3", new Double(3)));
list.add(new Data<String,Number>("4", new Double(4)));
int size = list.size();
for (int i = 0; i < size-1; i++) {
list.set(i, list.get(i+1));
}
list.remove(size-1);
}
The problem is that I get a null pointer exception at the line of setting the list. Shouldn't this code do what it's supposed to do? I check the size of the list and that returns 4. The only thing I can think of is that I'm missing something here and don't know how to properly set an element at the specified index?
Can you help me?
EDIT: Stacktrace:
Exception in thread "main" java.lang.NullPointerException
at javafx.scene.chart.XYChart$Series$1.onChanged(Unknown Source)
at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(Unknown Source)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(Unknown Source)
at javafx.collections.ObservableListBase.fireChange(Unknown Source)
at javafx.collections.ListChangeBuilder.commit(Unknown Source)
at javafx.collections.ListChangeBuilder.endChange(Unknown Source)
at javafx.collections.ObservableListBase.endChange(Unknown Source)
at javafx.collections.ModifiableObservableListBase.set(Unknown Source)
at mypackage.Controller.main(Controller.java:657)