java - Null Pointer Exception when filling a 2d array -


this question has answer here:

i'm building small game in applet. whenever try run it, following error on line buttons[i][k] = new activesquare(k);

error:

java.lang.nullpointerexception @ com.proj3.renee.clickaid.<init>(clickaid.java:21) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:57) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:526) @ java.lang.class.newinstance(class.java:379) @ sun.applet.appletpanel.createapplet(appletpanel.java:795) @ sun.applet.appletpanel.runloader(appletpanel.java:724) @ sun.applet.appletpanel.run(appletpanel.java:380) @ java.lang.thread.run(thread.java:745) 

i've read on similar answers , newinstance0 issues , i've checked make sure classes within activesquare working, still can't place problem. suggestions or further reading appreciated. here's first bit of code , constructor (i can post more if requested):

public class clickaid extends applet implements actionlistener { activesquare[][] buttons; private static final long serialversionuid = 1l;  public clickaid() {      setlayout(new gridlayout(0, 2, 5, 5));     jpanel panel = new jpanel();     add(panel);      (int = 0; < 4; ++i){//default = 4             (int k = 0; k < 6; ++k){                     buttons[i][k] = new activesquare(k); //this error                     panel.add(buttons[i][k].buttonaspect);                     buttons[i][k].buttonaspect.addactionlistener(this);         }     }        } 

you have initialize buttons[i] element of array. buttons[i] = new activesquare[6]


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -