我的应用程序应在primefaces终端中显示 JBoss server.log
文件。我读了这个文件,但是收到以下消息:
SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http--127.0.0.1-8080-1) javax.el.ELException: /tmp.xhtml @72,109 commandHandler="#{terminalController.handleCommand(command)}": java.lang.NullPointerException
XHTML代码:
<h:form >
<p:focus for="terminal" />
<p:terminal id="terminal" widgetVar="term" commandHandler="#{terminalController.handleCommand(command)}/>
</h:form>
终端控制器:
@ManagedBean(name = "terminalController")
public class TerminalController {
String sCurrentLine;
String sCurrentLineArray[];
Integer i=0;
BufferedReader br;
public TerminalController() {
}
public String handleCommand(String command) throws IOException,FileNotFoundException {
this.br = new BufferedReader(
new FileReader(
"/home/jboss-as-7.1.1.Final/standalone/log/server.log"));
if(command.equals("start")){
while ((sCurrentLine = br.readLine()) != null) {
return sCurrentLine;
}
return "end";
}
else
return command + " not found";
}
}
答案 0 :(得分:0)
错误发生在:
if(command.equals("start")){
....
}
我不知道command
来自何处,但如果 null ,并且您尝试将其与另一个字符串进行比较,则java会抛出异常。
修复:
if(command != null && command.equals("start"){
....
}
您可能会检查它是否也为空if (command != null && !command.isEmpty() && command.equals("start"))