Primefaces终端导致java.lang.NullPointerException

时间:2014-01-23 11:41:34

标签: jsf primefaces terminal

我的应用程序应在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";

    }
} 

1 个答案:

答案 0 :(得分:0)

错误发生在:

 if(command.equals("start")){
  ....
 }

我不知道command来自何处,但如果 null ,并且您尝试将其与另一个字符串进行比较,则java会抛出异常。

修复:

if(command != null && command.equals("start"){
....
}

您可能会检查它是否也为空if (command != null && !command.isEmpty() && command.equals("start"))