0

我有 2 节课 -DevTask. Tasks在计划阶段分配给Devs。我的计划变量之一assignedDev具有如下设置器:

public void setAssignedDev(Dev dev){
    this.assignedDev=dev;       
    dev.addToTasksAssigned(this); //null pointer exception here
            }

我需要保留task已分配给Dev班级中每个开发人员的 s 的日志,因此我有必要参考此任务。

当我运行求解器时,我收到以下错误消息:

31:53.968 [main] INFO  o.o.core.impl.solver.DefaultSolver - Solving started: time spend (222), score (null), new best score (-36000hard/0soft), random seed (0).
Exception in thread "main" java.lang.IllegalStateException: The property (assignedDev) setter on bean of class (class taskassignment.domain.Task) throws an exception.
at         org.optaplanner.core.impl.domain.common.ReflectionPropertyAccessor.executeSetter(ReflectionPropertyAccessor.java:80)
at org.optaplanner.core.impl.domain.variable.PlanningVariableDescriptor.setValue(PlanningVariableDescriptor.java:308)
at org.optaplanner.core.impl.heuristic.selector.move.generic.ChangeMove.doMove(ChangeMove.java:66)
at org.optaplanner.core.impl.constructionheuristic.decider.ConstructionHeuristicDecider.doMove(ConstructionHeuristicDecider.java:101)
at org.optaplanner.core.impl.constructionheuristic.decider.ConstructionHeuristicDecider.decideNextStep(ConstructionHeuristicDecider.java:73)
at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicSolverPhase.solve(DefaultConstructionHeuristicSolverPhase.java:67)
at org.optaplanner.core.impl.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:190)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:155)
at taskassignment.app.TaskAssignmentHelloWorld.main(TaskAssignmentHelloWorld.java:39)
Caused by: java.lang.NullPointerException
at taskassignment.domain.Task.setAssignedDev(Task.java:119)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.optaplanner.core.impl.domain.common.ReflectionPropertyAccessor.executeSetter(ReflectionPropertyAccessor.java:75)
... 8 more

此错误来自 ReflectionPropertyAccessor 类(在 Optaplanner 软件中)中的此子句,当它调用 bean 时Object

public void executeSetter(Object bean, Object value) {
    try {
        writeMethod.invoke(bean, value);
    } catch  //..... blah blah

此类如何设法提供该类的实例Task,但仍会生成空异常?task显然不是 null (我什至使用子句检查过)if(this!=null),那么它怎么能传递一个 null 值呢?

有解决方法吗?

如果我不清楚,请告诉我。非常感谢

4

1 回答 1

1

我假设您从未初始化的解决方案开始,并让构造启发式方法对其进行初始化。在未初始化的解决方案中,所有Task实例都以assignedDev设置为的属性开始 null。在 CH 期间,Solver 会定期将该assignedDev属性设置为非空Dev实例,然后通过将其设置回 来撤消该更改null。(撤消的原因与可扩展性和性能的增量分数计算有关。)

因此,在撤消过程中,它会调用writeMethod.invoke(someTask, null);,哪个调用someTask.setAssignedDev(null),哪个 NPE's on null.addToTasksAssigned(someTask);。合乎逻辑。

于 2014-04-17T06:13:15.880 回答