我得到一个java.lang.NullPointerException:
尝试调用方法 java.lang.String.trim()
时从 org.w3c.dom.Node.getTextContent()
返回的对象的.
当我使用时
List<String> welcomeFiles = WebXml.INSTANCE.getWelcomeFiles();
来自 ManagedBean,如下所示:
@ManagedBean
@RequestScoped
public class LogoffControl implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* log4j logger
*/
protected static final Logger LOGGER = LogFactory
.getLogger(LogoffControl.class);
public String logoff() {
List<String> welcomeFiles = WebXml.INSTANCE.getWelcomeFiles();
try {
Faces.redirect(welcomeFiles.get(0));
} catch (IOException e) {
LOGGER.error("Redirect Failed: " + e.getMessage());
}
Faces.invalidateSession();
return "";
}
}
我得到一个NullPointerException
,说我的 web.xml 中可能有拼写错误。我调试了一下,看到WebXML.java第414行xpath执行的结果成功了,我就进入到第418行的循环了
welcomeFiles.add(welcomeFileList.item(i).getTextContent().trim());
在调试器中welcomeFileList.item(i)
计算结果为<welcome-file>index.jsp</welcome-file>
,但是调用welcomeFileList.item(i).getTextContent()
结果为空。我不明白...我错过了什么?
在日志中:
Jan 11, 2015 1:36:37 PM org.omnifaces.config.WebXml init
SEVERE: WebXml failed to initialize. Perhaps your web.xml contains a typo?
java.lang.NullPointerException: while trying to invoke the method java.lang.String.trim() of an object returned from org.w3c.dom.Node.getTextContent()
at org.omnifaces.config.WebXml.parseWelcomeFiles(WebXml.java:418
SAPNetweaver 7.4 服务器上的 Oracle JSF 2.1.26、Omnifaces 1.8.1、servlet 2.5、sapjvm6.1 (Java6)。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>tablemaint-web</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
....
</webapp>
最佳答案
这是所使用的 JAXP 解析器中的一个错误。这应该可以正常工作。 SAP JAXP 解析器显然无法将文本节点识别为文本节点。 getTextContent()
即返回 null
例如文档节点和文档类型节点。
使用 getFirstChild().getNodeValue()
而不是 getTextContent()
的解决方法似乎工作正常(并且应该继续在像样的 JAXP 解析器上正常工作) ,所以这就是 implemented修复程序已在今天的 1.11 snapshot 中提供。 (以及 2.1 snapshot 对于 2.x 用户)。
关于jsf-2 - Omnifaces 1.8.1 WebXML 解析异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27890614/