我需要帮助确定我的空指针异常来自哪里

时间:2014-07-28 20:04:30

标签: java jsf primefaces

我正在使用PrimeFaces 4.0,与两个xhtml页面关联的NetBeans。 xhtml呈现选择的一个无线电菜单,用户可以从中选择他们想要更多信息的实验。当他们这样做时,我希望xhtml将实验作为字符串传递回java。在用户点击提交后,我想要打开另一个xhtml页面,用户可以从中进一步缩小搜索条件。截至目前,当用户单击“提交”时,会出现空指针异常。此外,使用System.out.println(),我可以看到java没有从网页上获取字符串,因为我的Glassfish服务器输出打印(部分):"信息:nullaaaaaaaaaaaaaaaaaaaaa"。它根本不打印其他println()。

XHTML部分

            <h:form>
                <h:panelGrid>
                    <p:selectOneRadio id="Test"  value="Please Selecte a Test">
                        <p:ajax update="Test"  partialSubmit="#{targetBeantFranz.selectedNameOfExperiments}"/>
                        <f:selectItems  value="#{targetBeantFranz.nameofexperiments}" />
                    </p:selectOneRadio>
                    <h:commandButton value="Select" action="open" />

                </h:panelGrid>
            </h:form>

以下是受影响的Java方法(整个JAVA文件比这长得多):

@ManagedBean(name = "targetBeantFranz", eager = true)
@SessionScoped

public class TargetBeanFranz implements Serializable {

public String selectedNameOfExperiments;
private final Map<String, String> nameofexperiments;

public TargetBeanFranz() throws SQLException {

        nameofexperiments = new HashMap<String, String>();

        XYexpdataServiceAdapter xydata = new XYexpdataServiceAdapterImpl();

        List<String> dbnameofexperiments = xydata.getNameofexperiments();
        for (String ta : dbnameofexperiments) {
            nameofexperiments.put(ta, ta);
        }
    }

    public String getSelectedNameOfExperiments() {
        System.out.println(selectedNameOfExperiments + "aaaaaaaaaaaaaaaaaaaaa");
        return selectedNameOfExperiments;
    }

    public void setSelectedNameOfExperiments(String selectedNameOfExperiments) {
        System.out.println(selectedNameOfExperiments + "bbbbbbbbbbbbbbbbbbbbbbbbb");
        this.selectedNameOfExperiments = selectedNameOfExperiments;
    }
}
    public Map<String, String> getNameofexperiments() {
        return nameofexperiments;
    }
}

ETA:我的堆栈跟踪看起来像这样:

显示java.lang.NullPointerException     at javax.faces.component.SelectItemsIterator $ MapIterator.next(SelectItemsIterator.java:346)     at javax.faces.component.SelectItemsIterator $ MapIterator.next(SelectItemsIterator.java:315)     在javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:155)     在javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:64)     在javax.faces.component.SelectUtils.matchValue(SelectUtils.java:86)     在javax.faces.component.UISelectOne.validateValue(UISelectOne.java:153)     在javax.faces.component.UIInput.validate(UIInput.java:983)     at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)     在javax.faces.component.UIInput.processValidators(UIInput.java:712)     在javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)     在javax.faces.component.UIForm.processValidators(UIForm.java:253)     在javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)     在javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)     在org.primefaces.component.layout.Layout.processValidators(Layout.java:233)     在javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)     在javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)     在javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)     at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)     在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)     在com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)     在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)     在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)     在org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)     在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)     在com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)     在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)     在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)     在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)     在com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)     在org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)     在org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)     在org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)     在org.glassfish.grizzly.filterchain.ExecutorResolver $ 9.execute(ExecutorResolver.java:119)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)     在org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)     在org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)     在org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)     在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)     在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access $ 100(WorkerThreadIOStrategy.java:55)     在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy $ WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)     在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:564)     在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:544)     在java.lang.Thread.run(Thread.java:745)

2 个答案:

答案 0 :(得分:2)

检查此article以获取有关JSF UI组件<h:selectOneMenu>的更多信息。

答案 1 :(得分:0)

可能是你需要在bean的构造函数中初始化:selectedNameOfExperiments