I know most people make the mistake of not initializing the Arraylist and that's why they get the NullPointerException.
But in my class i have initialized my Arraylist and I still get the exception when I try to add to it.
protected int V;
protected int E;
protected boolean[][] adjacencyMatrix;
public int i;
public int[] num;
public ArrayList<String> edges;
public SimpleGraph(int V) {
this.V = V;
this.E = 0;
this.adjacencyMatrix = new boolean[V][V];
edges = new ArrayList<String>();
num = new int[V];
}
public void DFS(int V) {
num[V] = i++;
for(int u = 0; u < getV(); u++)
{
if(adjacencyMatrix[V][u] == true && u != V)
{
if(num[u] == 0)
{
Integer temp = new Integer(num[u]);
edges.add("anything");
DFS(u);
}
}
}
}
You can assume that I have correctly added to the adjacencyMatrix.
Why do I get a NullPointerException when I try adding to the Arraylist?