java - 无法初始化速度
当我调用 Velocity.init() 时,出现以下异常。我已包含所有依赖项,我尝试设置属性并使用属性文件,但均无济于事。有什么帮助吗?
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:97)
at org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:543)
at org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:519)
at org.apache.velocity.runtime.RuntimeInstance.setDefaultProperties(RuntimeInstance.java:416)
at org.apache.velocity.runtime.RuntimeInstance.initializeProperties(RuntimeInstance.java:628)
at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:261)
at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:112)
at org.apache.velocity.app.Velocity.init(Velocity.java:74)
这是调用代码
import com.syntatik.roborm.RobormEntity;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.Properties;
public class Generator{
protected VelocityContext context;
public Generator(){
Velocity.init();
this.context = new VelocityContext();
}
}
When I call Velocity.init() I get the following exception. I have included all dependencies, I have tried setting properties and using property files but all to no avail. any help?
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:97)
at org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:543)
at org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:519)
at org.apache.velocity.runtime.RuntimeInstance.setDefaultProperties(RuntimeInstance.java:416)
at org.apache.velocity.runtime.RuntimeInstance.initializeProperties(RuntimeInstance.java:628)
at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:261)
at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:112)
at org.apache.velocity.app.Velocity.init(Velocity.java:74)
here is the calling code
import com.syntatik.roborm.RobormEntity;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.Properties;
public class Generator{
protected VelocityContext context;
public Generator(){
Velocity.init();
this.context = new VelocityContext();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我查看了 Velocity 源代码,可以看到它在类路径上找到默认属性文件,然后在 Reader.java 中遇到问题。使用 IDE,您应该能够获取 Reader.java 的源代码,以找出它获得 NPE 的原因。不幸的是,目前我无法查看
Reader
来为您提供更多信息。如果您无法确定 NPE 的原因,我建议您从类路径中删除默认属性文件并在代码中设置属性。
查看此问题了解更多信息
I have looked at the Velocity source code and can see that it's finding the default properties file on your classpath and then it's having trouble in Reader.java. With an IDE you should be able to get the source to Reader.java to find out why it's getting the NPE. Unfortunately at the moment I can't look at
Reader
to give you more information.If you can't determine the cause of the NPE, I suggest you delete the default property file from your classpath and set the properties in code.
Have a look at this question for more information