AngelJanniee
AngelJanniee

Reputation: 623

Jasper Report cannot find the class path

I am new to jasper report. I am using the JasperReport latest version 6.0.3, So I am having the problem to load the report which I created to print the billing. then I got the error message like below,

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)

Here is my sample code;

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

Previous Stacks did not solve my problem, anyone can guide me to go ahead????

Upvotes: 0

Views: 3897

Answers (2)

user4869492
user4869492

Reputation:

This one is help worked for me,

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

Try this one, and inform me.

Upvotes: 0

user1791574
user1791574

Reputation: 1749

You did not add / before src. that's why you are getting the error.

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

Hope it will help you.

Upvotes: 2

Related Questions