-
FEATURED COMPONENTS
First time here? Check out the FAQ!
asked 2013-02-27 13:18:53 +0800
This post is a wiki. Anyone with karma >100 is welcome to improve it.
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();
}
}
answered 2013-02-27 13:23:25 +0800
This post is a wiki. Anyone with karma >100 is welcome to improve it.
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
answered 2013-02-28 09:18:41 +0800
This post is a wiki. Anyone with karma >100 is welcome to improve it.
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>
Asked: 2013-02-27 13:18:53 +0800
Seen: 42 times
Last updated: Feb 28 '13