java.io.PrintWriter.write中的java.lang.NullPointerException [英] java.lang.NullPointerException at java.io.PrintWriter.write

查看:668
本文介绍了java.io.PrintWriter.write中的java.lang.NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 PrimeFaces'< p :wizard> 组件,我得到以下错误:

While running an application with PrimeFaces' <p:wizard> component, I am getting following error:

java.lang.NullPointerException
    at java.io.PrintWriter.write(PrintWriter.java:473)
    at com.sun.faces.application.view.WriteBehindStateWriter.write(WriteBehindStateWriter.java:127)
    at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.write(HtmlResponseWriter.java:666)
    at org.primefaces.component.wizard.WizardRenderer.encodeStepStatus(WizardRenderer.java:236)
    at org.primefaces.component.wizard.WizardRenderer.encodeMarkup(WizardRenderer.java:158)

这是如何造成的以及如何解决这个问题?

How is this caused and how can I solve this?

推荐答案

你显然使用PrimeFaces 3.0,它仍然处于非最终阶段。这个显然是PrimeFaces中的一个bug。您需要将它报告给PF伙伴,以便他们能够修复它。

You're apparently using PrimeFaces 3.0 which is still in non-final stage. This one is clearly a bug in PrimeFaces. You need to report it to the PF guys so that they can fix it.

我自己也经常看到这个愚蠢的异常,当某些PrimeFaces 3.0组件缺少明显的强制属性时。例如,

I've myself also regularly seen this silly exception when an apparent mandatory attribute was missing from some PrimeFaces 3.0 component. For example,

<p:selectOneMenu>
  <f:selectItem itemValue="foo" />
</p:selectOneMenu>

上述方法完美地适用于< h:selectOneMenu> 。项目值已被用作组件的值和标签。这也是如何指定< f:selectItem> 来工作的。但是,PrimeFaces < p:selectOneMenu> 期望 itemLabel 属性总是以某种原因出现并通过 null 属性值,而不事先直接检查响应编写器,这反过来会引发一个完全混淆的 NullPointerException 你得到了一个。添加 itemLabel 属性解决此问题:

The above works perfectly fine with <h:selectOneMenu>. The item value is been used as both the value and label of the component. That's also how the <f:selectItem> is been specified to work. But yet, the PrimeFaces <p:selectOneMenu> expects the itemLabel attribute to be always present for some reason and passes the null attribute value without checking beforehand straight to the response writer, which in turn throws a completely confusing NullPointerException, exactly the one which you got. Adding the itemLabel attribute solves it:

<p:selectOneMenu>
  <f:selectItem itemValue="foo" itemLabel="foo" />
</p:selectOneMenu>

我不知道< p:wizard>中的任何类似问题。 (我从来没有用过),但是你可能想尝试复制展示示例 1:1,然后基于此创建,而不是从头开始创建一个没有任何指导。

I am not aware of any similar issues in <p:wizard> (I've never used it), but you might want to try to copy the code of the showcase example 1:1 and then build further based on that, instead of creating one from scratch without any guidelines.

这篇关于java.io.PrintWriter.write中的java.lang.NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆