nullpointerexception - BlueJ call to public method null pointer exception (java.awt.container) -


normally instantiate panels inside of makeframe method, instead i'm required use 2 separate methods of createbuttonpanel() , createtextpanel(). problem being cannot work out how let makeframe use these when not inside of it's own method, , when i'm used javascript i've done looks should work, doesn't.

enter image description here

from screenshot, creating local variable in createbuttonpanel method making unavailable (null) add method of container.

public void createbuttonpanel() {     jpanel buttonpanel = new jpanel(); } 

instead, make assign new instance class level variable won't null when passing add method of container.

public void createbuttonpanel() {     this.buttonpanel = new jpanel(); // assigning class member } 

this should fix problem. also, advised move initializer method constructor calls , make private there no use of making public in case.

hope helps.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -