zoukankan      html  css  js  c++  java
  • freemarker报错之三

    1、错误描述

    Expression students is undefined on line 30, column 24 in student.ftl.
    The problematic instruction:
    ----------
    ==> list students as student [on line 30, column 17 in student.ftl]
    ----------
    
    Java backtrace for programmers:
    ----------
    freemarker.core.InvalidReferenceException: Expression students is undefined on line 30, column 24 in student.ftl.
    	at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
    	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:100)
    	at freemarker.core.Environment.visit(Environment.java:221)
    	at freemarker.core.MixedContent.accept(MixedContent.java:92)
    	at freemarker.core.Environment.visit(Environment.java:221)
    	at freemarker.core.Environment.process(Environment.java:199)
    	at freemarker.template.Template.process(Template.java:259)
    	at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
    	at com.you.test.freemarker.FreemarkerTest.student(FreemarkerTest.java:127)
    	at com.you.test.freemarker.FreemarkerTest.testStudent(FreemarkerTest.java:113)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    五月 27, 2014 10:45:07 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error
    严重: Template processing error: "Expression students is undefined on line 30, column 24 in student.ftl."
    
    Expression students is undefined on line 30, column 24 in student.ftl.
    The problematic instruction:
    ----------
    ==> list students as student [on line 30, column 17 in student.ftl]
    ----------
    
    Java backtrace for programmers:
    ----------
    freemarker.core.InvalidReferenceException: Expression students is undefined on line 30, column 24 in student.ftl.
    	at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
    	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:100)
    	at freemarker.core.Environment.visit(Environment.java:221)
    	at freemarker.core.MixedContent.accept(MixedContent.java:92)
    	at freemarker.core.Environment.visit(Environment.java:221)
    	at freemarker.core.Environment.process(Environment.java:199)
    	at freemarker.template.Template.process(Template.java:259)
    	at com.you.freemarker.FreemarkerTemplate.printFile(FreemarkerTemplate.java:109)
    	at com.you.test.freemarker.FreemarkerTest.studentFile(FreemarkerTest.java:141)
    	at com.you.test.freemarker.FreemarkerTest.testStudent(FreemarkerTest.java:114)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    
    
    Expression students is undefined on line 30, column 24 in student.ftl.
    The problematic instruction:
    ----------
    ==> list students as student [on line 30, column 17 in student.ftl]
    ----------
    
    Java backtrace for programmers:
    ----------
    freemarker.core.InvalidReferenceException: Expression students is undefined on line 30, column 24 in student.ftl.
    	at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
    	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:100)
    	at freemarker.core.Environment.visit(Environment.java:221)
    	at freemarker.core.MixedContent.accept(MixedContent.java:92)
    	at freemarker.core.Environment.visit(Environment.java:221)
    	at freemarker.core.Environment.process(Environment.java:199)
    	at freemarker.template.Template.process(Template.java:259)
    	at com.you.freemarker.FreemarkerTemplate.printFile(FreemarkerTemplate.java:109)
    	at com.you.test.freemarker.FreemarkerTest.studentFile(FreemarkerTest.java:141)
    	at com.you.test.freemarker.FreemarkerTest.testStudent(FreemarkerTest.java:114)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    2、错误原因

    /**
    	 * 测试freemarker中的list
    	 * @Title:testList
    	 * @Description:
    	 * @param:
    	 * @return: void
    	 * @throws
    	 */
    	@Test
    	public void testList()
    	{
    		List<Student> students = Arrays.asList(new Student("张三丰","男",26,new Date(1988-12-12),"湖北省武汉市武昌洪山区",78451214),
    											  new Student("李雪","女",20,new Date(1991-12-18),"湖北省武汉市武昌",85451214),
    											  new Student("刘刘","男",22,new Date(1989-10-18),"湖南省长沙市",96551214),
    											  new Student("吴明","女",21,new Date(1990-12-18),"广东省深圳市",56132012));
    		root.put("students", students);
    		ft.printFtl("stu.ftl",root);
    	}


    3、解决办法

  • 相关阅读:
    from __future__ import with_statement
    第六章 Flask数据库(二)
    python面向对象基础(四)内置方法 __xx__之new与init
    MySQL用户自定义变量
    iOS不得姐项目--appearance的妙用,再一次设置导航栏返回按钮,导航栏左右按钮的封装(巧用分类)
    iOS边练边学--NSURLSessionDataTask实现文件真正的断点续传
    iOS边练边学--AFNetWorking框架GET、Post、Download、Upload,数据解析模式以及监控联网状态
    iOS边练边学--NSURLSession、NSURLSessionTask的介绍与使用以及url中包含了中文的处理方法
    iOS开发小技巧--边接受数据边写入文件的两种方法
    iOS边练边学--文件压缩和解压缩的第三方框架SSZipArchive的简单使用
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315082.html
Copyright © 2011-2022 走看看