SWT / JFACE向导侦听器NullPointerException

时间:2012-08-15 18:09:45

标签: java nullpointerexception swt jface

我在swt / jface应用程序中开发向导,当我在页面中触发事件时,我有一个空指针异常。

以下是页面:

public class CompanySellerPage extends WizardPage {

public final static String PAGE_NAME = "Fournisseur Page" ;

public Button companyExistButton ;
public Button companyDontExistButton ;

public Combo companiesCombo ;
private String[] companies ;

public Text companyNameField ;
public Text companyAdressField ;
public Text companyNumberField ;

private Listener listener ;

public CompanySellerPage() {
    super(PAGE_NAME) ;
}

public void createControl(Composite parent) {

    // create the base composite the hold other widgets 
    Composite composite = new Composite(parent , SWT.NONE) ;

    // create the layout 
    GridLayout gl = new GridLayout(2, false) ;
    composite.setLayout(gl) ;

    createWidgets(composite) ;

    companyExistButton.addListener(SWT.Selection, listener) ;
    companyDontExistButton.addListener(SWT.Selection, listener) ;

    setControl(composite) ;

}


public void setListener(Listener listener) {
    this.listener = listener ;
}

// createWidgets(Composite parent) ...

}

这是听众

public class CompanySellerPageListener implements Listener {

private CompanySellerPage page ;
private Log log = LogFactory.getLog(CompanySellerPageListener.class) ;

public void setPage(CompanySellerPage page) {
    this.page = page ;
}

public void handleEvent(Event e) {

    if (e.widget == page.companyExistButton && ((Button)e.widget).getSelection() == true) {
        log.info("e.widget == page.getCompanyExistButton && getSelection == true") ;

        page.getCompanyNameField().setEnabled(false) ;
        page.getCompanyAdressField().setEnabled(false) ;
        page.getCompanyNumberField().setEnabled(false) ;
    }
    if (e.widget == page.companyExistButton && ((Button)e.widget).getSelection() == false) {
        log.info("e.widget == page.getCompanyExistButton && getSelection == false") ;
        page.getCompanyNameField().setEnabled(true) ;
        page.getCompanyAdressField().setEnabled(true) ;
        page.getCompanyNumberField().setEnabled(true) ;
    }
    if (e.widget == page.companyDontExistButton && ((Button) e.widget).getSelection() == true) {
        log.info("e.widget == page.getDontCompanyExistButton && getSelection == true") ;
        page.getCompaniesCombo().setEnabled(false) ;
    }
    if (e.widget == page.companyDontExistButton && ((Button)e.widget).getSelection() == false) {
        log.info("e.widget == page.getDonCompanyExistButton && getSelection == false") ;
        page.getCompaniesCombo().setEnabled(true) ;
    }
}
}

向导显示良好,当我点击两个按钮之一时,我有一个nullpointerexception ..

     [java] java.lang.NullPointerException
 [java]     at org.marsamaroc.mmapp.control.basiclisteners.CompanySellerPageListener.handleEvent(Unknown Source)
 [java]     at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
 [java]     at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
 [java]     at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3588)
 [java]     at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3209)
 [java]     at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
 [java]     at org.eclipse.jface.window.Window.open(Window.java:801)
 [java]     at org.marsamaroc.mmapp.control.basiclisteners.AddEquipementListener.widgetSelected(Unknown Source)
 [java]     

等。

我迷路了..

编辑: 我用spring来实例化页面和监听器..

<bean id="companySellerPage"
    class="org.marsamaroc.mmapp.presentation.wizards.CompanySellerPage">
    <property name="listener" ref="companySellerPageListener" />
</bean>

<bean id="companySellerPageListener"
    class="org.marsamaroc.mmapp.control.basiclisteners.CompanySellerPageListener">
    <property name="page" ref="companySellerPage" />
</bean>

现在我认为这不是一个好主意..所以我使用内部听众..

0 个答案:

没有答案