Fix NullPointerException when selected an version item in download.VersionsPage

This commit is contained in:
huangyuhui
2018-02-27 20:05:05 +08:00
parent 41dbdfc016
commit 3606186975
2 changed files with 7 additions and 1 deletions

View File

@@ -40,6 +40,7 @@ import org.jackhuang.hmcl.ui.wizard.WizardPage;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
public final class VersionsPage extends StackPane implements WizardPage, Refreshable {
@@ -93,6 +94,8 @@ public final class VersionsPage extends StackPane implements WizardPage, Refresh
chkOld.selectedProperty().addListener(listener);
list.getSelectionModel().selectedItemProperty().addListener((a, b, newValue) -> {
if (newValue == null)
return;
controller.getSettings().put(libraryId, newValue.getRemoteVersion().getSelfVersion());
callback.run();
});
@@ -114,6 +117,7 @@ public final class VersionsPage extends StackPane implements WizardPage, Refresh
}
else return true;
})
.filter(Objects::nonNull)
.sorted()
.map(VersionsPageItem::new).collect(Collectors.toList());
}

View File

@@ -30,6 +30,8 @@ import org.jackhuang.hmcl.download.liteloader.LiteLoaderRemoteVersionTag;
import org.jackhuang.hmcl.download.optifine.OptiFineRemoteVersion;
import org.jackhuang.hmcl.ui.FXUtils;
import java.util.Objects;
/**
* @author huangyuhui
*/
@@ -47,7 +49,7 @@ public final class VersionsPageItem extends StackPane {
private StackPane imageViewContainer;
public VersionsPageItem(RemoteVersion<?> remoteVersion) {
this.remoteVersion = remoteVersion;
this.remoteVersion = Objects.requireNonNull(remoteVersion);
FXUtils.loadFXML(this, "/assets/fxml/download/versions-list-item.fxml");
lblSelfVersion.setText(remoteVersion.getSelfVersion());