赞
踩
操作逻辑的时候,使用了set集合,但是出现了空指针,排除了很久,发现有一个低级错误,没有初始化set,导致没有set对象,所以无法使用set的方法
Set<String> starHeadUrl = null;
//如果超过三个,就显示前三个,如果不够三个,就全部显示
if(listAllFriendsVos1.isPresent()){
List<AppendMomentStarVo> listAllNOFriendsVos = listAllFriendsVos1.get();
int i = listAllNOFriendsVos.size();
Map<String, AppendMomentStarVo> collect =
listAllNOFriendsVos.stream().collect(Collectors.toMap(AppendMomentStarVo::getHeadurl,
Function.identity(),(key1, key2) -> key2));
int count = configLogic.getValue2Integer(ConfigLogic.COUNT_STAR_HEADURL);
logger.info("listNOMomentstar:count{}::i{}",count,i);
if(i<=count){
starHeadUrl = collect.keySet();
}else{
Set<String> set = collect.keySet();
String[] arr = new String[set.size()];
String[] strings = set.toArray(arr);
logger.info("string.length:{}",strings.length);
starHeadUrl = new TreeSet<>();
for (int a=0;a<count;a++){
starHeadUrl.add(strings[a]);
}
}
错误的地方:
如果在【2】位置没有初始化set,,那么,在添加的时候会出现空指针,因为这个时候的set是null,没有初始化,所以对象不存在,是空的!!!!!
在初始化了set之后,就可以正常添加了。
引以为戒!!!!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。