0

Nullpointer exception in ListModelList

asked 2013-02-27 13:18:53 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-02-27 13:18:53 +0800

princess1986 gravatar image princess1986
1

Hi Team,

I am getting Nullpointer exception at below line. listbox.setModel(new ListModelList<string>(list));

where listbox is the id of Listbox.

Please find the below code.Here zk is the properties file.Please help me in this regard.

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

    try{

        ResourceBundle rb = ResourceBundle.getBundle("zk");
        Enumeration <String> keys = rb.getKeys();
        List <String> list = new ArrayList<String>();  
        while (keys.hasMoreElements()){
            String key=keys.nextElement();
            String value=rb.getString(key);
            list.add(value);
            Collections.sort(list); 
            listbox.setModel(new ListModelList<String>(list)); 
            listbox.setSelectedIndex(0);


            }


catch (Exception e)
    {
    e.printStackTrace();
    }

}

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-02-27 13:23:25 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-02-27 13:23:25 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Which architecture you are using MVC or MVVM if you used MVC architecture and Wired your listbox something like this..

@Wire("listbox")
Listbox listbox;

then in aftercompose method you have to add this line....

public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {

Selectors.wireComponents(view, this, true);
//Other code here
}

then Wiring will work if this is not the case then please edit your question with more code. Thanks

link publish delete flag offensive edit
0

answered 2013-02-28 09:18:41 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-02-28 09:18:41 +0800

princess1986 gravatar image princess1986
1

Hi,

Still I am getting nullpointer exception.I am using MVC and i tried with your logic but still getting the same error.

I am providing additional code.May be it will help me.

LoginViewCtrl.java

package tutorial;

import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.ResourceBundle; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Sessions; import org.zkoss.zk.ui.select.SelectorComposer; import org.zkoss.zk.ui.select.Selectors; import org.zkoss.zk.ui.select.annotation.Listen; import org.zkoss.zk.ui.select.annotation.Wire; import org.zkoss.zul.Button; import org.zkoss.zul.ListModelList; import org.zkoss.zul.Listbox; import org.zkoss.zul.Textbox; import org.zkoss.zul.Window;

public class LoginViewCtrl extends SelectorComposer<window >{<="" p="">

private static final long serialVersionUID = 1L;

@Wire
private Textbox nameTxb; 

@Wire
private Textbox passwordTxb;

@Wire private Button confirmBtn1, confirmBtn2 ,confirmBtn4;

 @Wire
 private Listbox listbox;
@Override
 public void doAfterCompose (Window view) throws Exception {
    super.doAfterCompose(view);
    Selectors.wireComponents(view, this, true);
    try{

        ResourceBundle rb = ResourceBundle.getBundle("zk");
        Enumeration <String> keys = rb.getKeys();
        List <String> list = new ArrayList<String>();  
        while (keys.hasMoreElements()){
            String key=keys.nextElement();
            String value=rb.getString(key);
            list.add(value);



            /* To sort out the properties file*/

            Collections.sort(list); 


            listbox.setModel(new ListModelList<String>(list));
            listbox.setSelectedIndex(0);
        }


     }

catch (Exception e)
    {
    e.printStackTrace();
    }
    }

}

Below is login1.zul file.

<window id="loginWin" border="normal" width="500px" title="Login Page" apply="tutorial.LoginViewCtrl" mode="overlapped" position="center,center" ><="" p="">

<grid>
    <rows>
        <row> UserName:* <textbox id="nameTxb" type="text" constraint="no empty"/></row>
        <row> Password:* <textbox id="passwordTxb"  type="password" constraint="no empty"/></row>

    <row>
        Domain:*
        <hlayout>
            <listbox id  = "listbox" mold="select" rows ="1" width="133" >

                </listbox>

                </hlayout>
    </row>

<row spans="3"> <hbox> <button id="confirmBtn1" label="SignIn"/> <label id="mesgLbl1"/> <button id="confirmBtn2" label="Reset"/> <label id="mesgLbl2"/>

  <button id="confirmBtn4" label="SignUp"/>
  <label id="mesgLbl4"/> 
</hbox></row>


</rows>
</grid>>

</window>

link publish delete flag offensive edit

Comments

First do not post question in answer section you have to edit your question..Second thing see how i m using afterCompose in my example use as i used it will work pass argument of component class as i passed

sjoshi ( 2013-02-28 16:26:56 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-02-27 13:18:53 +0800

Seen: 42 times

Last updated: Feb 28 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More