This question already has answers here:
What is a NullPointerException, and how do I fix it?
                                
                                    (12个答案)
                                
                        
                                9个月前关闭。
            
                    
我试图从字段isActive设置为N或null的列表对象中过滤掉。不幸的是,我在方法过滤器中得到了NullPointerException,我不知道这是怎么回事?

码:

...
return dictionary.getAllPermissions().stream()
            .filter(Objects::nonNull)
            .filter(z->"N".equals(z.getIsActive().toString()) || z.getIsActive().equals(null)) //field isActive is Character
            .collect(Collectors.toList());

最佳答案

您的订购错了,应该是:

.filter(z -> z.getIsActive() == null || "N".equals(z.getIsActive().toString()))

09-30 13:28