OptaPlanner中不明原因的NPE

时间:2018-05-16 14:04:12

标签: java nullpointerexception optaplanner

我的OptaPlanner程序中出现了无法解释的NullPointerException:

09:52:08.016 [main] INFO  org.reflections.Reflections - Reflections took 44 ms to scan 1 urls, producing 5 keys and 5 values 
09:52:08.163 [main] INFO  o.o.core.impl.solver.DefaultSolver - Solving started: time spent (17), best score (-191hard/3350soft), environment mode (REPRODUCIBLE), random (JDK with seed 0).
Exception in thread "main" java.lang.NullPointerException
    at org.optaplanner.core.impl.solver.recaller.BestSolutionRecaller.updateBestSolution(BestSolutionRecaller.java:128)
    at org.optaplanner.core.impl.solver.recaller.BestSolutionRecaller.updateBestSolution(BestSolutionRecaller.java:123)
    at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.phaseEnded(DefaultConstructionHeuristicPhase.java:154)
    at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.solve(DefaultConstructionHeuristicPhase.java:102)
    at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:87)
    at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:173)
    at JantermRunner.main(JantermRunner.java:28)

这是我第一次使用OptaPlanner,所以我完全相信我在某个地方蠢蠢欲动,但这个错误并没有给我任何关于我出错的信息,因为所有引用的行都是OptaPlanner代码。 (JantermRunner第28行只是对solver.solve的调用)

编辑:要清楚 - 我确实理解空指针异常是什么,我只是不知道如何设置我的OptaPlanner程序的方式不会导致某个地方出现问题。

1 个答案:

答案 0 :(得分:0)

我敢打赌你正在使用EasyScoreCalculator并将null作为Score返回。

我会调整OptaPlanner,以便在这种情况下提供良好的错误信息。