im a biginner in java ,im trying to create a rubber band dynamic graph but when i ran my program it came back with these errors : Exception in thread "main" java.lang.NullPointerException
- at Node.add_neighbour(Node.java:58)
- at Graph.add(Graph.java:32)
public class Node {
private static final double FRICTION = -0.8;
Vector position;
Vector velocity;
Set<Node> Neighbours;
boolean Mobile, Rigid;
public Node(Vector vector) {
Vector vector1 = new Vector(0, 0);
this.Rigid = false;
this.Mobile = true;
Set<Node> myNodes = new HashSet<>();
}
public void add_neighbour(Node node) {
Neighbours.add(node); //**the 1st error is indicated in this line**
}
}
2nd error:
import java.util.HashSet;
import java.util.Set;
public class Graph {
Set<Node> nodes = new HashSet<>();
public Set<Node> getNodes() {
return nodes;
}
public void add(Node node) {
nodes.add(node);
}
public void add(Node node1, Node node2) {
node1.add_neighbour(node2);//2nd***
node2.add_neighbour(node1);//2nd****
}
}