Jasper Report 找不到 class 路径

Jasper Report cannot find the class path

我是 jasper 报告的新手。我正在使用 JasperReport 最新版本 6.0.3,所以我无法加载我创建的用于打印帐单的报告。然后我收到如下错误消息,

net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: I:\Projects\Testsrc\com\thus\test\Blank_A4_Landscape.jrxml (The system cannot find the path specified)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:221)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:192)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:183)
    at com.thus.test.Test.main(Test.java:29)
Caused by: java.io.FileNotFoundException: I:\Projects\Testsrc\com\thus\test\Blank_A4_Landscape.jrxml (The system cannot find the path specified)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:216)

这是我的示例代码;

try {
        connection = getConnection("jdbc:sqlserver://xxx.xxx.xx.xx:1433;DatabaseName=Thusya");

        JasperDesign jasperDesign = JRXmlLoader.load(new File("")
                .getAbsolutePath()
                + "src/com/thus/test/Blank_A4_Landscape.jrxml");
        String sqlString = "SELECT * FROM TABLE1 WHERE CNO = '156801'";
        JRDesignQuery designQuery = new JRDesignQuery();
        designQuery.setText(sqlString);
        jasperDesign.setQuery(designQuery);

        JasperReport jasperReport = JasperCompileManager
                .compileReport(jasperDesign);
        JasperPrint jasperPrint = JasperFillManager.fillReport(
                jasperReport, null, connection);

        JasperViewer.viewReport(jasperPrint);

    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

之前的Stacks没有解决我的问题,谁能指导我继续????

你没有在src前加上/。这就是您收到错误的原因。

JasperDesign jasperDesign = JRXmlLoader.load(new File("")
            .getAbsolutePath()
            + "/src/com/thus/test/Blank_A4_Landscape.jrxml");

希望对您有所帮助。

这个对我有用,

JasperDesign jasperDesign = JRXmlLoader.load(new File(
    "C:/New folder/Blank_A4_Landscape.jrxml"));

试试这个,然后通知我。