PDA

View Full Version : error while running



Anonymous
09-23-2002, 02:06 PM
Hi Everybody,

I 'm getting following exception while running the program
Plz. help me ...

D:\murali\reports>java TestReport
Exception in thread "main" java.lang.NoClassDefFoundError: com/jrefinery/report/io/ReportGenerator
at TestReport.parseReport(TestReport.java:14)
at TestReport.previewReport(TestReport.java:27)
at TestReport.main(TestReport.java:35)


Here is my program...

import java.io.*;
import java.sql.*;
import java.net.*;
import com.jrefinery.report.*;
import com.jrefinery.report.io.ReportGenerator;
import com.jrefinery.report.util.CloseableTableModel;
import com.jrefinery.report.util.ResultSetTableModelFactory;


public class TestReport {

private JFreeReport parseReport(URL templateURL) {
JFreeReport result = null;
ReportGenerator generator = ReportGenerator.getInstance();
try {
result = generator.parseReport(templateURL);
} catch (Exception e) {
System.out.println("Error while parsing ");
}
return result;
}

protected void previewReport() {
JFreeReport report = null;
if (report == null) {
URL in = getClass().getResource("customer_report.xml");
report = parseReport(in);
report.setData(getData());
}

}

public static void main(String arg[]){
TestReport t= new TestReport();
t.previewReport();
}

public CloseableTableModel getData(){
ResultSetTableModelFactory theTab =null;
CloseableTableModel theTable = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con =null;
con = DriverManager.getConnection("jdbc:odbc:murali", "talk411", "talk411");

Statement stmt = con.createStatement();
String theQuery = "select count(customer_id) from customer";
ResultSet theResultSet = stmt.executeQuery(theQuery);

if(theResultSet.next()){
theTab = new ResultSetTableModelFactory();
theTable = theTab.createTableModel(theResultSet);
System.out.println("No. of Customers registered to date "+ theResultSet.getInt(1));
}
} catch (Exception e) {
System.err.println("problems connecting to ");
}
return theTable;
}
}

Thanks
Murali

Anonymous
09-23-2002, 03:07 PM
Hi,

your classpath is incomplete ... Java does not know anyting about the JFreeReport-library and its required helper libraries.

Try running your programm with

java -cp jfreereport-0.7.6.jar;gnujaxp.jar;itext-0.94.jar;jcommon-0.7.0.jar;junit.jar;pixie.jar;bsh-1.2b6.jar;. TestReport

Maybe you have to adjust the classpath entries to fit your system, so assuming you have extracted JFreeReport in a directory called c:\jfreereport, you will have to write

java -cp c:\jfreereport\jfreereport-0.7.6.jar;c:\jfreereport\gnujaxp.jar;c:\jfreereport\itext-0.94.jar;c:\jfreereport\jcommon-0.7.0.jar;c:\jfreereport\junit.jar;c:\jfreereport\pixie.jar;c:\jfreereport\bsh-1.2b6.jar;. TestReport

and make sure that you don't forget the ";." at the end of the classpath setting, or you will get another ClassNotFoundException complaining that the class TestReport cannot be found.

Another thing for performance reasons: Try to enable scrollable result sets in your statement. Try to create a statement using the alternative factory method by writing:

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

or

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

Support for scrollable resultsets depends on the driver implementation, if in doubt query the DatabaseMetaData (or catch the SQLException thrown on the statement creation).

ResultSets that are not scrollable are read completly and all contents are copied into a DefaultTableModel. This is not funny when querying a larger set of rows, having to copy (in worst case) several megabytes is poison for performance. Scrollable resultsets (one of TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE) are more advanced and allow random access to the resultset data (and so makes the copying of the resultset contents unnessesary).

Have more fun,
said Thomas

Anonymous
09-24-2002, 09:13 PM
Hi Thomas,
I crossed that problem and entered into another ...

In my program i passing resultset to ClosableTableModel classes createTableModel method. its giving the following exception. I'm sure that the query returns results

Can u help me to cross this.

D:\murali\reports>java -cp c:\jfreereport-0.7.6\jfreereport-0.7.6.jar;c:\jfreereport-0.7.6\gnujaxp.jar;c:\jfreereport-0.
7.6\itext-0.94.jar;c:\jfreereport-0.7.6\jcommon-0.7.0.jar;c:\jfreereport-0.7.6\junit.jar;c:\jfreereport-0.7.6\pixie.jar;
c:\jfreereport-0.7.6\bsh-1.2b6.jar;. TestReport
problems connecting to java.lang.ClassCastException: [Ljava.lang.Object;
Exception in thread "main" java.lang.NullPointerException: Data must not be null
at com.jrefinery.report.JFreeReport.setData(JFreeReport.java:575)
at TestReport.previewReport(TestReport.java:28)
at TestReport.main(TestReport.java:35)

Thanks in advance for your support
Murali

Anonymous
09-25-2002, 02:03 PM
Hi,

your function getData seems to return null (there is a debug-message "problems connecting to" issued on every exception and also in the problem report ...

The TableModel for the report must not be null, the NullPointerException is thrown because your Model is null (the exception caused no programm error, instead an null-value is returned).

The ClassCastException message in your problem report seems to cause all the trouble, try to trace this error and for sure you'll find the bug.

Have more fun,
said Thomas

sid
01-10-2007, 08:02 AM
class S
{
public static void main(String arg[])
{
System.out.println("JAVA");
}
}
the program compiles but on running gives the error
Exception in thread main java.lang.noclassdeffounderror:

Taqua
01-10-2007, 02:55 PM
http://java.sun.com/developer/onlineTraining/new2java/

Go ahead, read a bit, it wont hurt you. We all started with Java some time ago - but we usually started reading a book on the topic or took a deep look at one of the various tutorials.

Have fun,
said Thomas