我有 2 节课 -Dev
和Task
. Tasks
在计划阶段分配给Dev
s。我的计划变量之一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 值呢?
有解决方法吗?
如果我不清楚,请告诉我。非常感谢