[英]StringTemplate 4 NullPointerException
I 've got NullPointerException 我有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)
and console log: "templates 11:82: '(' came as a complete surprise to me" for my template: 和控制台日志:我的模板“模板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();
>> >>
I guess, there is a problem with 'for-statement', cause after it had been deleted, everything worked. 我猜想,“ for-statement”存在问题,因为删除后,一切正常。
UPDATE: found solution in doc - http://www.antlr.org/wiki/display/ST4/StringTemplate+cheat+sheet http://www.antlr.org/wiki/display/ST/How+to+Allow+Double+Angle+Brackets+as+a+String 更新:在文档中找到了解决方案-http: //www.antlr.org/wiki/display/ST4/StringTemplate+cheat+sheet http://www.antlr.org/wiki/display/ST/How+to+Allow+ Double + Angle + Brackets + as + a + String
I should use '\\<' for prevents '<' from starting an attribute expression 我应该使用'\\ <'来防止'<'启动属性表达式
Looks like it cannot handle method invocations inside a for-loop declaration. 看起来它无法处理for循环声明中的方法调用。 Instead of
代替
for (i = 0; i < variable.getRowDimension(); i++)
try 尝试
int variableRowDimension = variable.getRowDimension();
for (i = 0; i < variableRowDimension; i++)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.