gpt4 book ai didi

java - java中的静态和非静态?

转载 作者:行者123 更新时间:2023-12-01 17:16:54 25 4
gpt4 key购买 nike

错误:

Cannot make a static reference to the non-static method setSelectedInfoRole(SelectOption) from the type PeopleInfoViewModel.PeopleInfoData

代码如下:

    @Command
@NotifyChange({ "peopleInfoList", "selectedFolderInfo" })
public void encryptInfo() {
Set selectedPeopleInfo=peopleInfoList.getSelection();
if (selectedPeopleInfo == null) {
showError(pageResourceBundle.getText("PLS_SELECT_AN_INFO_TO_CRYPT"));
return;
}
List<PeopleInfoRecord> folderRecord = new ArrayList<PeopleInfoRecord>();


for (Object selectedObj : selectedPeopleInfo) {
if (selectedObj instanceof PeopleInfoData) {
PeopleInfoData peopleInfoData = (PeopleInfoData) selectedObj;
ValidInfoRow validInfoRow = Services.folderService().findValidInfoByInfoCode(peopleInfoData.getPeopleInfoRecord().getInfoCode());

if (InfoType.CHOOSE.equals(validInfoRow.getInfoType())) {
if (!CsdcStringUtils.isBlank(peopleInfoData.getPeopleInfoRecord().getInfoValue(), true)) {
PeopleInfoData.setSelectedInfoRole(new SelectOption<String>(peopleInfoData.getPeopleInfoRecord().getInfoValue()));
}
}

}
}
}

在上面的方法行

   PeopleInfoData.setSelectedInfoRole(new SelectOption<String>(peopleInfoData.getPeopleInfoRecord().getInfoValue()));

给出错误。

这是 Pojo 类:

public class PeopleInfoData {
private ListModelList<SelectOption<String>> infoobj;

private PeopleInfoRecord peopleInfoRecord;
private SelectOption<String> selectedInfoRole;


public SelectOption<String> getSelectedInfoRole() {
return selectedInfoRole;
}

public void setSelectedInfoRole(SelectOption<String> selectedInfoRole) {
this.selectedInfoRole = selectedInfoRole;
}

public ListModelList<SelectOption<String>> getInfoobj() {
return infoobj;
}

public void setInfoobj(ListModelList<SelectOption<String>> infoobj) {
this.infoobj = infoobj;
}

}

最佳答案

setSelectedInfoRole() 是一个非静态方法,您尝试以静态方式调用它PeopleInfoData. setSelectedInfoRole 这是错误的。您需要创建该类的对象,然后调用该方法。

new PeopleInfoData().setSelectedInfoRole(new SelectOption<String>(peopleInfoData.getPeopleInfoRecord().getInfoValue()));

但看起来您已经为该类创建了一个对象。您需要使用该对象来调用此方法。

PeopleInfoData peopleInfoData = (PeopleInfoData) selectedObj;
peopleInfoData.setSelectedInfoRole(new SelectOption<String>(peopleInfoData.getPeopleInfoRecord().getInfoValue()));

关于java - java中的静态和非静态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21399351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com