0

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
https://github.com/chillw...

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

 <zk>
 <style src="style.css"/>
    <window title="待辦事項" border="normal" hflex="1" vflex="1"
        contentStyle="overflow:auto"
        viewModel="@id('vm') @init('controller.DoSomethingVM')">
        <borderlayout>
            <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>
                    </hbox>
                    <listbox vflex="1" model="@bind(vm.doListModel)" mold="paging" pageSize="5" selectedItem="@bind(vm.selectedTodo)">
                        <listhead>
                            <listheader width="60px">已完成</listheader>
                            <listheader>事項</listheader>
                            <listheader hflex="min">刪除</listheader>
                        </listhead>
                        <template name="model">
                            <listitem sclass="@bind(each.complete?'complete-todo':'')">
                                <listcell>
                                    <checkbox checked="@bind(each.complete)" onCheck="@command('completeTodo',todo=each)"/>
                                </listcell>
                                <listcell>
                                    <label value="@bind(each.subject)" />
                                </listcell>
                                <listcell>
                                    <button>刪除</button>
                                </listcell>
                            </listitem>
                        </template>
                    </listbox>
                </vlayout>
            </center>
            <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>
                    </hbox>
                    <grid hflex="1">
                        <columns>
                            <column align="left" hflex="min" />
                            <column />
                        </columns>
                        <rows>
                            <row>
                                <cell sclass="row-title">重要性:</cell>
                                <cell>
                                    <radiogroup>
                                        <radio label="重要" />
                                        <radio label="普通" />
                                        <radio label="不重要" />
                                    </radiogroup>
                                </cell>
                            </row>
                            <row>
                                <cell sclass="row-title">日期:</cell>
                                <cell>
                                    <datebox width="200px" value="@bind(fx.date)"></datebox>
                                </cell>
                            </row>
                            <row>
                                <cell sclass="row-title">地點:</cell>
                                <cell>
                                    <listbox width="100px"
                                        mold="select">
                                        <listitem selected="true"
                                            label="台北市" />
                                        <listitem label="新北市" />
                                    </listbox>
                                    <!--                                 這裡再頁面一跑出來時就初始化 -->
                                </cell>
                            </row>
                            <row>
                                <cell sclass="row-title">說明:</cell>
                                <cell>
                                    <textbox hflex="1" height="200px"
                                        multiline="true" value="@bind(fx.description)">
                                    </textbox>
                                </cell>
                            </row>
                        </rows>
                    </grid>
                    <hlayout>
                        <button label="更新資料" onClick="@command('updateTodo')"></button>
                        <button label="重新載入"></button>
                    </hlayout>
                </vlayout>
            </east>
        </borderlayout>
    </window>
</zk>

DoSomethingVM:

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;

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

    @Command
    public void completeTodo(@BindingParam("todo") DoSomethingBean bean){
        bean=service.update(bean);

        }
    @Command
    @NotifyChange({"selectedTodo","subject"})
    public void addTo(){
        if(Strings.isBlank(subject)){
            Clients.showNotification("請輸入要記錄的事情");
        }
        DoSomethingBean bean=service.saveTodo(new DoSomethingBean(subject));
        doListModel.add(bean);
//      selectedTodo = service.saveTodo(temp);
//      doListModel.add(selectedTodo);
//      doListModel.addToSelection(selectedTodo);
        subject=null;

    }

    @Command
    @NotifyChange("selectedTodo")
    public void updateTodo(){
        selectedTodo=service.update(selectedTodo);
        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() {
        System.out.println("selectedTodo="+selectedTodo);
        return selectedTodo;
    }
    public void setSelectedTodo(DoSomethingBean selectedTodo) {

        this.selectedTodo = selectedTodo;
        System.out.println(selectedTodo);
    }


}

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

delete flag offensive retag edit

Comments

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

Follow
1 follower

RSS

Stats

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