Reputation: 661
I'm getting UnsupportedOperationException
when I add an elemnt into my ObservableList<List<String>>
.
The code (here I'm trying to add columns in my dynamic tableview):
private ObservableList<List<String>> fnlData;
.
.
fnlData = FXCollections.observableList(jdata);
.
.
public void addColumn(){
for (int i = 0; i < fnlData.size(); i++){
if (fnlData.get(i)!=null && fnlData.get(i).size() > indexC) {
fnlData.get(i).add(indexC, ""); // <- here occurs the error
}
}
finalTable.getSelectionModel().clearSelection();
finalTable.getItems().clear();
finalTable.getColumns().clear();
createColumns(clms++);
finalTable.getItems().addAll(fnlData);
}
Upvotes: 0
Views: 162
Reputation: 661
Ok, I solved it...
I changed this:
private List<List<String>> jdata = new LinkedList<>();
String[] splitted;
.
.
splitted=(lines.split(";"));
jdata.add(Arrays.asList(splitted));
into this:
private List<List<String>> jdata = new LinkedList<>();
String[] splitted;
.
.
splitted=(lines.split(";"));
LinkedList ll = new LinkedList(Arrays.asList(splitted));
jdata.add(ll);
Because the inner list (List<String>
) of jdata was a ArrayList, but I needed a LinkedList...
Thanks to ljgw
Upvotes: 1
Reputation: 989
An implementation of a collection is free to implement as many operations as it pleases, throwing an UnsupportedOperationException
if the operation is not implemented. I advise you to check the documentation of the particular collection you are using.
Upvotes: 0