i was coding a puzzle program. When i compiled my Java program, it was successful. But when i run it, it shows
Solution to problem using breadth first :
Exception in thread "main" java.lang.NullPointerException
at SolvingProblem.isGoal(SolvingProblem.java:24)
at AbstractTreeSearch.solve(AbstractTreeSearch.java:31)
at EightP.main(EightP.java:15)
I spent several hours and fixing the code but unsuccessful. Ideally, it is supposed to show 3x3 array configuration. Could anyone help me here and point out what is the problem?
State initialState = new State(State.arrayA);
State GoalState = new State(State.arrayG);
@Override
public Object getInitialState() {
return initialState;
}
@Override
public boolean isGoal(Object state) {
return state.equals(GoalState);
}
Another class below
public Node solve(Problem problem) {
//initialize the search tree using the initial state of problem
frontier = initFrontier();
frontier.addAll(expand(new Node(problem.getInitialState()), problem));
//Starting frontier
boolean done = false;
Node solution = null;
while (!done) {
if (frontier.isEmpty()) {
System.out.println("Blank frontier");
done = true;
} else {
Node node = chooseLeafNode(frontier, problem);
//inspecting node
if (problem.isGoal(node.getState())) {
System.out.println("Solution found");
System.out.println();
solution = node;
done = true;
} else {
//Expanding node, frontier is..
frontier.addAll(expand(node, problem));
}
}
}