java - Nullpointer Exception when assigning value to Integer array -


this seems bit strange me. created static integer array , trying assign value it. null pointer exception @ degree[i] = 0 line.

since not reading value before assigning it, not understand why nullpointer exception.

private static integer[] degree; public static void initdegree(int num_of_vertices) throws exception{     (int = 0; < num_of_vertices; i++) {         degree[i] = 0;     } } 

you need initialize array.

ex

degree = new integer[5]; 

otherwise, array null.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -