我已经尝试在Platform.runLater()中包装ObservableList,但是它给了我一个错误:
从内部类引用的局部变量必须是final或 有效的最终
我无法解决任何问题以解决此错误。这是我的代码:
Task task = new Task<Void>() {
@Override public Void call() {
try {
for (int i = 0; i < obLstDataset.size(); i++){
// **************************
//doing other stuff here
// **************************
if (pageVLEDEResult.contains("something")) {
Platform.runLater(new Runnable() {
@Override
public void run() {
obLstInvalid.add((String)obLstDataset.get(i));
}
});
}
else if (pageVLEDEResult.contains("something else")){
if (i!=0){
i--;
}
}
updateProgress (i+1, obLstDataset.size());
}
} catch (IOException | FailingHttpStatusCodeException ex) {
Logger.getLogger(VehicleLicenceExpiryDateEnquirer.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
};
答案 0 :(得分:0)
我认为您需要在runLater final中访问变量。此外,在for循环中修改for循环变量(在本例中为i)是非常糟糕的做法。所以我把它重写成了一个while循环。
Task task = new Task<Void>() {
@Override public Void call() {
try {
int i=0;
do {
// **************************
//doing other stuff here
// **************************
if (pageVLEDEResult.contains("something")) {
final List <not sure what class this is> fobLstInvalid = obLstInvalid;
final List <not sure what class this is> fobLstDataset = obLstDataset;
final int fi = i;
Platform.runLater(new Runnable() {
@Override
public void run() {
obLstInvalid.add((String)obLstDataset.get(fi));
}
});
}
else if (pageVLEDEResult.contains("something else")){
if (i!=0){
i--;
}
}
updateProgress (i+1, obLstDataset.size());
i++;
} while (i < obLstDataset.size())
} catch (IOException | FailingHttpStatusCodeException ex) {
Logger.getLogger(VehicleLicenceExpiryDateEnquirer.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
};