I have found many related post here but couldn't get my answer.Why this run-time error ?
static List<Integer>[] adj = (List<Integer>[]) new ArrayList[1000];
public static void main(String[] args) {
int edge, u, v, source;
Scanner input = new Scanner(System.in);
edge = input.nextInt();
for (int i = 0; i < edge; i++) {
u = input.nextInt();
v = input.nextInt();
adj[v].add(u); // Null pointer Exception
adj[u].add(v); // Null pointer Exception
}
ArrayList
) is being created. docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html – madth3 Oct 24 '12 at 19:17