nullpointer exception pls help

asked 2017-06-02 06:26:31 +0800

sun455154 gravatar image sun455154
1 1

updated 2017-06-05 08:53:48 +0800

chillworld gravatar image chillworld flag of Belgium
5357 4 9

I cannot use formbinding ,if i use that will appear nullpointerexception help.. i use mvvm design patternIts my code below.

 <style src="style.css"/>
    <window title="待辦事項" border="normal" hflex="1" vflex="1"
        viewModel="@id('vm') @init('controller.DoSomethingVM')">
            <center autoscroll="true" border="none">
                <vlayout hflex="1" vflex="1">
                    <hbox hflex="1">
                        <textbox value="@bind(vm.subject)" onOK="@command('addTo')" hflex="1" placeholder="輸入要記錄的事情..."></textbox>
                        <button onClick="@command('addTo')" width="50px">送出</button>
                    <listbox vflex="1" model="@bind(vm.doListModel)" mold="paging" pageSize="5" selectedItem="@bind(vm.selectedTodo)">
                            <listheader width="60px">已完成</listheader>
                            <listheader hflex="min">刪除</listheader>
                        <template name="model">
                            <listitem sclass="@bind(each.complete?'complete-todo':'')">
                                    <checkbox checked="@bind(each.complete)" onCheck="@command('completeTodo',todo=each)"/>
                                    <label value="@bind(each.subject)" />
            <east visible="@bind(not empty vm.selectedTodo)" border="none" width="300px"
                splittable="true" maxsize="600">
                <vlayout form="@id('fx') @load(vm.selectedTodo)">
                    <hbox align="center" hflex="1">
                        <checkbox checked="@bind(fx.complete)"></checkbox>
                        <textbox hflex="1" value="@bind(fx.subject)"></textbox>
                    <grid hflex="1">
                            <column align="left" hflex="min" />
                            <column />
                                <cell sclass="row-title">重要性:</cell>
                                        <radio label="重要" />
                                        <radio label="普通" />
                                        <radio label="不重要" />
                                <cell sclass="row-title">日期:</cell>
                                    <datebox width="200px" value="@bind(fx.date)"></datebox>
                                <cell sclass="row-title">地點:</cell>
                                    <listbox width="100px"
                                        <listitem selected="true"
                                            label="台北市" />
                                        <listitem label="新北市" />
                                    <!--                                 這裡再頁面一跑出來時就初始化 -->
                                <cell sclass="row-title">說明:</cell>
                                    <textbox hflex="1" height="200px"
                                        multiline="true" value="@bind(fx.description)">
                        <button label="更新資料" onClick="@command('updateTodo')"></button>
                        <button label="重新載入"></button>


package controller;

import java.io.Serializable;
import java.util.List;

import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.lang.Strings;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.ListModelList;

import bean.DoSomethingBean;
import service.DoSomethingImpl;
import service.DoSomethingService;

public class DoSomethingVM implements Serializable{

    private static final long serialVersionUID = 1L;

    DoSomethingService service=new DoSomethingImpl();

    //data for the view
    String subject;
    ListModelList<DoSomethingBean> doListModel;
    DoSomethingBean selectedTodo;

    public void init(){
        List<DoSomethingBean> allTodo = service.getAllTodo();
        doListModel=new ListModelList<DoSomethingBean>(allTodo);

    public void completeTodo(@BindingParam("todo") DoSomethingBean bean){

    public void addTo(){
        DoSomethingBean bean=service.saveTodo(new DoSomethingBean(subject));
//      selectedTodo = service.saveTodo(temp);
//      doListModel.add(selectedTodo);
//      doListModel.addToSelection(selectedTodo);


    public void updateTodo(){
        doListModel.set(doListModel.indexOf(selectedTodo), selectedTodo);

    public DoSomethingService getService() {
        return service;
    public void setService(DoSomethingService service) {
        this.service = service;
    public String getSubject() {
        return subject;
    public void setSubject(String subject) {
        this.subject = subject;
    public ListModelList<DoSomethingBean> getDoListModel() {
        return doListModel;
    public void setDoListModel(ListModelList<DoSomethingBean> doListModel) {
        this.doListModel = doListModel;
    public DoSomethingBean getSelectedTodo() {
        return selectedTodo;
    public void setSelectedTodo(DoSomethingBean selectedTodo) {

        this.selectedTodo = selectedTodo;


when i add @id('fx')@load(vm.selectedTodo) will appear 500 nullpointerexception plz help me

delete flag offensive retag edit


maybe a stacktrace?

chillworld ( 2017-06-05 08:55:11 +0800 )edit

yea or maybe a simplified example reproducing the problem on http://zkfiddle.org/ ?

cor3000 ( 2017-06-12 02:19:45 +0800 )edit
Be the first one to answer this question!
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

1 follower



Asked: 2017-06-02 06:26:31 +0800

Seen: 15 times

Last updated: Jun 05 '17

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