Hi everyone!
I'm QUITE newbie as regards Java development, and I'm trying to build a simple MyApp that is able to generate reports (using JasperReports) from XLS files. My main class is quite simple actually, I only needed to generate a simple GUI that allow me to select the XLS and the jasper (compiled report template) file, and export the report to pdf (three buttons, three file choosers and two text areas).
Most of the reporting work is done by the already existent JasperReports (JR) libraries. I "only" need to call them, and provide them with the correct arguments. Of course, the problem is to know wich classes and methods are to be used, but after some research I managed to find it out (or at least I think so.
I'm using Netbeans 6.8 to help me write the code. I installed the JR plugin for NetBeans, wich takes care of installing JR libraries as well (it installs JasperReports 4.5.0 libs).
I started by creating a New Project, a Java Application, and designing the simple GUI interface. Once I had that resolved, I went on to writing the "important" part: importing the JR classes necessaries for my app, and actually generating the report.
After several attempts, and some more research, I managed to write a code that somehow, I believe, should work around.
The problem is that, for some reason I cannot figure out, when I import a certain JR class to my main class, it seems to works just fine. But then, while running the app, some of the JR classes that I call have problems finding it.
I'll try to explain it as clear as I can:
In my main class, I wrote:
import java.io.File; import java.io.IOException; import jxl.*; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFileChooser;
... and other imports.
Netbeans checks those packages, finds them, finds the classes inside them, and doesn't report any error.
Then, I generated the following method:
private JRXlsDataSource getDataSource() throws JRException { try { ds = new JRXlsDataSource(file); ds.setUseFirstRowAsHeader(true); } catch (IOException e) { throw new JRException(e); } return ds; }
JRXlsDataSource is a JR Class, which I imported in my app, along with all the other classes inside JR's libraries.
When I run my app, it returns an Exception, so I went on debugging it.
Running step-by-step, I realized that, when it comes to the point where I need to use methods inside the JRXlsDataSource class, it throws the exception that interrupts my app. If I select it, and use the Netbean's tool "Go to Source", Netbeans opens that class, and shows errors along some import sentences. Specifically that's what I see INSIDE the JRXlsDataSource.class code:
NetBeans_JRXlsDataSource_imports.jpg
If I try to write by hand, on that class, an import jxl.* sentence, Netbeans complains that the jxl package doesn't exist. Of course, that's not true. I added it to my app (I can see it in Netbeans' navigator), and if I try to import it to my main class, it works fine: Netbeans doesn't complain.
I'm not sure what is it that I'm doing wrong. I suppose it may have something to do with JR's libraries classpath, or something. But the fact that the main class CAN actually find it disorients me.
I wish someone here at the forum cold lend me a hand with this. And if I'm not clear enough, please let me know and I'll try to explain myself better.
Thanks in advance, and I hope you can help me solve my problem.
Abelinux