gpt4 book ai didi

java - Jasper Report 找不到类路径

转载 作者:行者123 更新时间:2023-12-02 04:45:51 26 4
gpt4 key购买 nike

我是 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();
}

之前的堆栈没有解决我的问题,任何人都可以指导我继续吗???

最佳答案

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

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

希望对您有帮助。

关于java - Jasper Report 找不到类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29664050/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com