简体   繁体   中英

Dynamic Reports : Showing error in compilation with NetBeans

I created a report from my NetBeans GUI and It was working fine, but all of a sudden the compiler showing error now.

package dreportsample;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import net.sf.dynamicreports.examples.Templates;
import net.sf.dynamicreports.report.builder.style.StyleBuilder;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.datasource.DRDataSource;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;

/**
 * @author Ricardo Mariaca (dynamicreports@gmail.com)
 */
public class DReportSample {

    public DReportSample() {
        build();
    }

    private void build() {  
            StyleBuilder boldStyle         = stl.style().bold();
            StyleBuilder boldCenteredStyle = stl.style(boldStyle).setHorizontalAlignment
                    (HorizontalAlignment.CENTER).setFontSize(15);
            StyleBuilder footerLeft         = stl.style().setHorizontalAlignment
                   (HorizontalAlignment.LEFT) ;
             StyleBuilder footerRight         = stl.style().setHorizontalAlignment
                   (HorizontalAlignment.RIGHT) ;
            //BufferedImage img = new BufferedImage(1200,1200,BufferedImage.TYPE_INT_RGB);
           BufferedImage img = null;
try {
   // img = ImageIO.read(new File("D:/Hysteresis.png"));
    img = ImageIO.read(new File("D:/Hysteresis.png"));
} catch (IOException e) {
}
       BufferedImage logo = null;
try {
   // img = ImageIO.read(new File("D:/Hysteresis.png"));
    logo = ImageIO.read(new File("D:/Logo.jpg"));
} catch (IOException e) {
}
        try {
            report()//create new report design
                         // .setColumnTitleStyle(boldStyle)
                         // .setColumnStyle(boldStyle)
                          .highlightDetailEvenRows()
              .columns(//add columns

                col.column(null,"Col_1",      type.stringType()),
                col.column(null,"Col_2",  type.stringType())
                                )
                           .summary(
        cmp.verticalList()
            .add(cmp.text("\n\nHYSTERISIS PLOT").setStyle(boldStyle))
            .add(cmp.text("A brief description of what this plot signifies "
                                + "which means that change in are related to"
                                + " pain relief and subsequently"
                                + "should be encouraged \n\n\n\n"))
           // .add(cmp.image(getClass().getResourceAsStream
             //     ("D:/Hysteresis.png")).setFixedDimension(300, 300))


            .add(cmp.image(img).setFixedDimension(400, 300))
            .add(cmp.text("ANALYSIS\n\n\n").setStyle(boldStyle))
            .add(cmp.text("REMARKS\n\n\n\n").setStyle(boldStyle))
            .add(cmp.text("Doctor Signature").setStyle(boldStyle))
    )
              .title(

                                cmp.horizontalList()
                                .add(
                                cmp.image(logo).setFixedDimension(70, 70),
                                cmp.verticalList()
                                .add(
                                cmp.text("Address Line 1").setStyle(boldCenteredStyle),
                                cmp.text("Address Line 2").setStyle(boldCenteredStyle),
                                cmp.text("Address Line 3").setStyle(boldCenteredStyle))
                                )

                                .newRow()
 .add(cmp.filler().setStyle(stl.style().setTopBorder(stl.pen2Point())).setFixedHeight(10))

                                )//shows report title

                              //  .pageFooter(cmp.pageXofY())//shows number of page at page footer
                                .pageFooter(
                                Templates.footerComponent,
                                 //cmp.text("Emsol Software Solution \t\t\t\t\t\t\t\t"
                               // + " copyright: gauravbvelelx@gmail.com")
                                cmp.horizontalList()
                                .add(cmp.text("Emsol Software Solution").setStyle(footerLeft),
                                cmp.text("copyright: gauravbvelex@gmail.com").setStyle(footerRight))
                                )

              .setDataSource(createDataSource())//set datasource
              .show();//create and show report
        } catch (DRException e) {
            e.printStackTrace();
        }
    }
    private JRDataSource createDataSource() {
        DRDataSource dataSource = new DRDataSource("Col_1", "Col_2");

        dataSource.add("Name","Sample");
                dataSource.add("Age","26");
                dataSource.add("Sex","Female");
                dataSource.add("Weight","53 Kg");
                dataSource.add("BMI","20");
                dataSource.add("Massage Duration (Mins)","4.5");
                dataSource.add("RPM","26");
                dataSource.add("Doctor Attended","Doctor");
                dataSource.add("Date","22-Feb-2013");

        return dataSource;
    }   


    public static void main(String[] args) {
        new DReportSample();
    }
}

This code worked fine just few hours back. But now it is suddenly showing error: Screen shot attached

在此处输入图片说明

Same kind of error it is showing at report() and other parts as well. Basically it is not able to recognize various classes and fields of dynamic reports library though the library has been imported successfully, though few hours back it was working well.

The way I am using dynamic reports is by adding the libraries as below:

1) Downloaded dynamicreports-3.1.0-project-with-dependencies
2) Unzipped
3) In my Netbeans Project
Libraries -> Add Jar/folder -> Selecting all files from dynamicreports-3.1.0-project-with-dependencies\dynamicreports-3.1.0\lib
Libraries -> Add Jar/folder -> Selecting all files from dynamicreports-3.1.0-project-with-dependencies\dynamicreports-3.1.0\dist

在此处输入图片说明

It worked fine, but then then I changed the name of the folder where I saved dynamicreports-3.1.0-project-with-dependencies, due to which It gave me Reference Error for added libraries. So I again rechanged it to previous name, but since then I am getting the error shown.

I have tried everything, building new project and following the steps mentioned or re downloading new dynamicreports-3.1.0-project-with-dependencies and again following the steps. But nothing seems to work, its frustrating as I was so close to complete my project.

Can anyone help please.

Thanks

Ok.. resolved it..

Below line got deleted causing the errors:

import static net.sf.dynamicreports.report.builder.DynamicReports.*;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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