0

我有 NullPointerException

java.lang.NullPointerException
at org.stringtemplate.v4.STGroup.loadTemplateFile(STGroup.java:663)
at org.stringtemplate.v4.STGroupDir.loadTemplateFile(STGroupDir.java:176)
at org.stringtemplate.v4.STGroupDir.load(STGroupDir.java:136)
at org.stringtemplate.v4.STGroup.lookupTemplate(STGroup.java:237)
at org.stringtemplate.v4.STGroup.getInstanceOf(STGroup.java:172)

和控制台日志:“模板 11:82: '(' 对我来说完全是一个惊喜”对于我的模板:

matrix(type, id, variable, path) ::= <<
new Runnable() {
    private <type> variable;
    private Runnable init (<type> var)
    {
        variable = var; return this;
    }
    @Override
    public void run() {
        int i=0, j=0; String matrix = "{";
        for (i = 0; i < variable.getRowDimension(); i++)
        {
            matrix += "{";
            for (j = 0; j < variable.getColumnDimension(); j++)
            {
                matrix += variable.get(i,j);
                if (j != variable.getColumnDimension() - 1)
                    matrix += ",";
                else 
                    matrix += "}";
            }
            if (i != variable.getRowDimension() - 1)
                matrix += ",";
        }
        matrix += "}";
        File file = new File("<path>");
        try {
            FileUtils.writeStringToFile(file, "<id>"+matrix);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }
}.init(<variable>).run();

>>

我想,'for-statement' 有问题,因为在它被删除后,一切正常。

更新:在文档中找到解决方案 - http://www.antlr.org/wiki/display/ST4/StringTemplate+cheat+sheet http://www.antlr.org/wiki/display/ST/How+to+Allow+双+角+括号+as+a+字符串

我应该使用 '\<' 来防止 '<' 启动属性表达式

4

0 回答 0