当前位置: 代码迷 >> Java Web开发 >> 请问一个freemaker 转换模板成word 输出时报空指针的有关问题
  详细解决方案

请问一个freemaker 转换模板成word 输出时报空指针的有关问题

热度:2842   发布时间:2013-02-25 21:10:55.0
请教一个freemaker 转换模板成word 输出时报空指针的问题
公司最近让做一个报表导出的WORD模板,用freemaker 做的,因为不会,所以先按别人写的,弄了个测试代码如下
Map<String, Object> dataMap = new HashMap<String, Object>(); 
Configuration configuration = new Configuration(); 
configuration.setDirectoryForTemplateLoading(new File("resources/")); 
configuration.setDefaultEncoding("UTF-8");
dataMap.put("name", "goddy"); 
dataMap.put("age", "11"); 
Template t = null; 
try { 
t = configuration.getTemplate("teste.vm"); 
} catch (IOException e) { 
e.printStackTrace(); 


File outFile = new File("D:/outFile.doc"); 
Writer out = null; 
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream( 
outFile), "UTF-8"));

t.process(dataMap, out); 

模板是我用得word2007 生成的一个DOC文件,然后改了扩展名为zip ,把里面的document文件里的内容复制出来的,现在我在运行到t.process(dataMap, out); 时候就报空指针,请问各位大神,这是为什么呢?我尝试换了一下别人写的模板(应该是没有问题的)也是这个情况,只要运行到这里就报空指针了,求指教!

------解决方案--------------------------------------------------------
看看 t 是否为空啊
  相关解决方案