java - null pointer exception while resizing arrays -
i have nullpointerexception
in line "newindexer[i].index = (int)double.positive_infinity;
" , cannot figure out why. appreciated.
public void resizeindexer(int newkey) { if (maxheap >= newkey) return; if (newkey > maxheap){ handle[] newindexer = new handle[newkey + 1]; (int = 0; < newkey; i++){ if (i < maxheap) newindexer[i] = this.indexer[i]; else{ system.out.println(i); newindexer[i].index = (int)double.positive_infinity; newindexer[i].status = false; } } maxheap = newkey; indexer = newindexer; } }
you have create new handle instance each new index of new array before modifying index
, status
members :
(int = 0; < newkey; i++){ if (i < maxheap) newindexer[i] = this.indexer[i]; else{ system.out.println(i); newindexer[i] = new handle (); newindexer[i].index = (int)double.positive_infinity; newindexer[i].status = false; } }
Comments
Post a Comment