i'm having a problem using choco on eclipse , i tried to add a constraint and i got a nullPointerException can anyone explain to me ?
public static void main(String[] args )
{
int n=8;
CPModel m=new CPModel();
IntegerVariable[] cells = new IntegerVariable[n+1];
for(int i = 1; i < 9; i++){
cells[i] = Choco.makeIntVar("x"+i, 1, 8);
m.addVariables(cells[i]);
}
IntegerVariable x = new IntegerVariable("X", 1, 8);
IntegerVariable y = new IntegerVariable("Y", 1, 8);
ComponentConstraint[] rows = new ComponentConstraint[n];
for(int i = 0; i < n; i++){
rows[i] =(ComponentConstraint) Choco.allDifferent(cells[i]);
m.addConstraints((choco.kernel.model.constraints.Constraint[]) rows);
}
System.out.println(m.pretty());
CPSolver s = new CPSolver();
//read the model
s.read(m);
//solve the problem
s.solve();
for(int i = 0; i < n; i++){
System.out.print(s.getVar(cells[i]).getVal()+" ");
}
System.out.println();
}
The following instruction is the source of the NullPointer exception :
m.addConstraints((choco.kernel.model.constraints.Constraint[]) rows);
Code of the error :
Exception in thread "main" java.lang.NullPointerException at choco.kernel.common.util.tools.ArrayUtils.getNonRedundantObjects(ArrayUtils.java:343) at choco.kernel.model.VariableArray.doExtractVariables(VariableArray.java:108) at choco.kernel.model.VariableArray.extractVariables(VariableArray.java:123) at choco.kernel.model.VariableArray.getVariableIterator(VariableArray.java:72) at choco.cp.model.CPModel.addConstraints(CPModel.java:896) at choco.cp.model.CPModel.addConstraints(CPModel.java:853) at Games.main(Games.java:27)