-3

我的项目有什么问题。我已经导入了所有依赖项,但它仍然输出错误:

输出错误

这是我导入的列表依赖项: 依赖包图像

这是我的测试代码:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package brouillon;

import controllers.RetardJpaController;
import entites.Retard;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import javax.persistence.Persistence;
import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;

/**
 *
 * @author Vals
 */
public class Brouillon {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        RetardJpaController ctr = new RetardJpaController(Persistence.createEntityManagerFactory("BrouillonPU"));
        List<Retard> liste = ctr.findRetardEntities();
        try(InputStream is = Brouillon.class.getResourceAsStream("ressources/object_collection_template.xls")) {
            try (OutputStream os = new FileOutputStream("object_collection_output.xls")) {
                Context context = new Context();
                context.putVar("retards", liste);
                //JxlsHelper.getInstance().processTemplate(is, os, context);
                JxlsHelper jh = JxlsHelper.getInstance();
                jh.processTemplate(is, os, context);
            }
        }
    }

}
4

1 回答 1

-1

这对我来说看起来不正确:

    try(InputStream is = Brouillon.class.getResourceAsStream("ressources/object_collection_template.xls")) {

注意拼写错误:"ressources". 这足以在查找中完成。尝试取出第二个's',看看它是否有效。

情况可能比那更糟。如果资源是代码源,那么它的内容将在 CLASSPATH 中,但文件夹本身不会。在这种情况下,您只需要文件名。

尝试查看您在运行时使用的 CLASSPATH 并查看其中的内容。这样就清楚了。

“我已经导入了所有依赖项”——这是你最大的问题。大多数初学者和没有经验的程序员都会陷入“我做的一切都是正确的——为什么计算机要迫害我?”这种态度的牺牲品。如果您采取以“我做错了什么?”开头和结尾的态度,您会变得更快。并无情地检查你的错误。

于 2015-12-13T14:18:45.620 回答