繁体   English   中英

Apache Android 中的速度(“无法找到资源”)

[英]Apache Velocity in Android("unable to find resource")

我使用此代码到达 temp.vm,但出现此错误。 我应该在代码、文件位置或 Mainfest 中进行哪些更改

PS 这是新项目,所以我有标准清单我试图将文件保存在资源、资产和主路径中

2021-05-20 17:11:27.617 17303-17303/com.example.printer E/org.apache.velocity:ResourceManager:无法在任何资源加载器中找到资源“123/temp.vm”。

    VelocityEngine velocityEngine = new VelocityEngine();
    velocityEngine.init();
    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    Template t = velocityEngine.getTemplate("123/temp.vm");
    VelocityContext context = new VelocityContext();
    context.put("name", "World");
    StringWriter writer = new StringWriter();
    t.merge( context, writer );

在此处输入图像描述

我不确定将模板文件放在 java 源代码树中是否足以让它们从类路径中可见。 我们需要查看您的 gradle 脚本。 通常,应该在类路径中的资源(通常将它们包含在最终的 jar 中)位于resources目录中。 在开发模式下,可以尝试手动将java目录添加到classpath中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM