java.lang.NullPointerException错误

由于对象没有没有new出来直接使用,提示该错误


private List authInfoList;

/*此处必须new粗来*/
authInfoList = new ArrayList() ;

AuthInfo authInfo = new AuthInfo();
authInfo.setGateName(gate.getName());

authInfo.setType(authorizations.get(i).getType());
authInfo.setTeam(authorizations.get(i).getTeam());
authInfo.setWeek(authorizations.get(i).getWeek());
authInfo.setStartTime(authorizations.get(i).getStartTime());
authInfo.setEndTime(authorizations.get(i).getEndTime());

authInfoList.add(authInfo);


@XmlRootElement(name="commandlist")
@XmlAccessorType(XmlAccessType.FIELD)
public class CommandList {
    @XmlElement(name="command")
    private List commandList;

    public List getCommandList(){return commandList;}
    public void setCommandList(List commandList){
        this.commandList = commandList;
    }
}

CommandList commandList = new CommandList() ;commandList.setCommandList( new ArrayList()) ; //必须加,否则空指针

for(int i=0; i; i++){
    Command command = new Command();
    command.setCmd("delIo");
    command.setGate(delIoBean.getGateNameList().get(i));
    command.setData("");

    commandList.getCommandList().add(command);
}


你可能感兴趣的:(java.lang.NullPointerException错误)