0

i m working on a ZK project , using ZK MVC approach. what i did try to do is to initalize "a panel" after doAfterCompose a div , but the problem is that i got a "java.lang.NullPointerException"

and those are a simple exemple of what i did try to do . My view "mypage.zul"

<zk>
<borderlayout>
     <west width="140px" splittable="true" collapsible="true" maxsize="140">
        <div align="center" apply="dashboard.display">
                    <label value="WorkLoad"></label><checkbox></checkbox>
        </div>
     </west>

     <center autoscroll="true"  >
      <div>
        <portallayout id="portalLayout" maximizedMode="whole" width="100%" >

            <portalchildren   >
                  <panel  id="panelworkload"   >
                        <panelchildren>  
                            <div width="100%"  >
                            <charts  id="workloadDay" type="column" />
                            </div>  
                        </panelchildren>
                  </panel>
             </portalchildren>            
         </portallayout> 
       </div>
    </center>

</borderlayout>
</zk>

My conroler : "display"

public class display extends SelectorComposer<Div>{

@Wire
Checkbox  objectif_checkbox;

@Wire
Panel  panelworkload;

public void doAfterCompose(Div comp) throws Exception {
    super.doAfterCompose(comp);

    panelworkload.setTitle("hello workload");

    }
}

and this is the exception that i got

java.lang.NullPointerException dashboard.display.doAfterCompose(display.java:24) dashboard.display.doAfterCompose(display.java:1) org.zkoss.zk.ui.impl.UiEngineImpl.doAfterCompose(UiEngineImpl.java:578) org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:880) org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:826) org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:735) org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:699)

what i have throught of it so far is that the div has been composed before the portallayout , that why the server cant reconize portallayout when div is created

can anyone help me pls ? i m kinda stuck here ...and thank you

elmetni hamza
  • 221
  • 1
  • 12
  • Either `panelworkload` is null or the Div passed to `doAfterCompose(comp)` is null. Duplicate of http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it – arserbin3 May 28 '14 at 15:53
  • no they are not null , when i delete this line "panelworkload.setTitle("hello workload");" it works just fine , and when i add it to an event it works too , none of them are null – elmetni hamza May 28 '14 at 15:57

1 Answers1

1

The setTitle method for zk framework's Panel object is the following:

public void setTitle(String title) {
    if (title == null)
    title = "";
    if (!Objects.equals(_title, title)) {
        _title = title;
        smartUpdate("title", _title);
    }
}

There is nothing in there that would throw a NullPointerException. (And the stack trace would indicate it)

Therefore, the panelworkload should currently be null in the doAfterCompose(comp) object.

I would recommend you read through several of the answers on What is a NullPointerException, and how do I fix it? , although they do not do a great job of explaining how to diagnose a NullPointerException error, nor how to follow a stack trace.

Panel Source Reference

Community
  • 1
  • 1
arserbin3
  • 6,010
  • 8
  • 36
  • 52