java - 无法初始化速度

发布于 2024-12-23 17:45:49 字数 1322 浏览 4 评论 0原文

当我调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行雁书 2024-12-30 17:45:49

我查看了 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文