【问题标题】:cqengine IndexedCollection add causing nullpointercqengine IndexedCollection 添加导致空指针
【发布时间】:2016-11-03 15:56:36
【问题描述】:

当我将元素添加到 IndexedCollection 时,我目前收到此错误:

HIGHEST: null
java.lang.NullPointerException
    at java.util.concurrent.ConcurrentSkipListMap.doGet(ConcurrentSkipListMap.java:778)
    at java.util.concurrent.ConcurrentSkipListMap.get(ConcurrentSkipListMap.java:1546)
    at com.googlecode.cqengine.index.support.AbstractMapBasedAttributeIndex.addAll(AbstractMapBasedAttributeIndex.java:81)
    at com.googlecode.cqengine.engine.CollectionQueryEngine$12.perform(CollectionQueryEngine.java:1125)
    at com.googlecode.cqengine.engine.CollectionQueryEngine.forEachIndexDo(CollectionQueryEngine.java:1206)
    at com.googlecode.cqengine.engine.CollectionQueryEngine.addAll(CollectionQueryEngine.java:1122)
    at com.googlecode.cqengine.ConcurrentIndexedCollection.add(ConcurrentIndexedCollection.java:351)

我尝试调试以查看是否传递了一个空值,但我没有。我要添加的对象有一个空 DateTime 但相应的索引已经返回空,而不是当它为空时。

我认为解决这个问题最终归结为经验,@npgall 你有没有遇到过这个问题,如果有,你是如何解决的?

【问题讨论】:

    标签: java cqengine


    【解决方案1】:

    我认为该网站上缺少该领域的文档。它提到了SimpleNullableAttributeMultiValueNullableAttribute,但没有真正解释何时使用它们。

    TL;DR 是:如果您获得 NPE,通常意味着您需要使用可为空的属性。

    或者更准确地说:如果您的数据有可能包含空值,那么您需要使用可空属性(例如SimpleNullableAttribute)而不是不可空属性(例如SimpleAttribute)。

    无论如何,我已经扩展了主要 Readme.md 上的文档以更详细地讨论“空值”。希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-02
      相关资源
      最近更新 更多