java - IntelliJ gui creator: JPanel gives runtime null pointer exception upon adding any component -


i having problem intellij's java gui creation. of code behind panel unfortunately hidden within gui creator , not editable me.

i created blank jpanel "questionpanel" itellij gridlayoutmanager. when try add panel, null pointer exception though panel not null. tried adding jtextfield layout (out of curiosity) , did not either. jtextfield shows up, still cannot add within code.

when change layout manager else (gridbaglayout, formlayout, borderlayout, etc.), no longer errors, nothing shows up.

displayview.java

private jpanel questionpane;  public void initialize() {     questionpane.addmouselistener(new mouselistener() {          @override         public void mousereleased(mouseevent e) {             questionpane.add(new jlabel("test"));             system.out.println("click event received.");         }         //other overrides hidden } 

does have idea of going on behind scenes or way me components onto panel? thanks.

sample stack trace (this trace not made same code above, same error):

exception occurred during event dispatching: java.lang.nullpointerexception  @ com.intellij.uidesigner.core.gridlayoutmanager.addlayoutcomponent( gridlayoutmanager.java:134)  @ java.awt.container.addimpl(container.java:1074) @ java.awt.container.add(container.java:365) @ [myproject].ui.view.displayview$1.actionperformed(displayview.java:91) @ javax.swing.abstractbutton.fireactionperformed(abstractbutton.java:1995) ..... 

for using intellij's gui creator , receiving same error, fixed problem manually setting panel's layout manager in code instead of choosing different layout managers within gui creator.

example:

questionpane.setlayout(new boxlayout(questionpane, boxlayout.page_axis)); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -