再次发帖,急求高手解决ireport报表问题!!
如下是我的代码,运行到jasperPrint =JasperFillManager.fillReport(jasperReport,reportParams,jrds);时,出现如下错误
Exception in thread "main"
java.lang.NullPointerException at
net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)
at page.myreport2.reportName(myreport2.java:67)
at page.myreport2.main(myreport2.java:84)
Java Result: 1
到底是怎么回事啊,急死了!!!
package page;
import java.io.File;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;
public class myreport2
{
public void reportName() throws JRException
{
JRResultSetDataSource jrds = null;
JasperPrint jasperPrint = null;
Map reportParams = new HashMap();
ResultSet rs = null;
Connection con = null;
java.sql.Statement stmt = null;
String sql = "select * from danci";
try
{
//动态获取
JasperDesign jasperDesign =new JasperDesign();
JasperReport jasperReport=(JasperReport)
JRLoader.loadObject("report4.jasper");
//jasperDesign=JRXmlLoader.load("report4");
// JasperReport jasperReport =JasperCompileManager.compileReport(jasperDesign);
//建立连接
con = DriverManager.getConnection("jdbc:sqlserver://localhost\\MSSQLSERVER:1433;databaseName=book","yuanxiaofei","123");
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
rs.next();
jrds = new JRResultSetDataSource(rs);
reportParams.put("parameter1", "missile");
if(jasperReport==null)
System.out.println("123");
if(jrds==null)
System.out.println("111");
if(reportParams==null)
System.out.println("123");
jasperPrint =JasperFillManager.fillReport(jasperReport,reportParams,jrds);//运行到这出问题了!!!
//调出JasperViewer进行打印预览
JasperViewer.viewReport(jasperPrint);
rs.close();
stmt.close();
con.close();
}
catch(
SQLException ex)
{
ex.printStackTrace();
}
}
public static void main(String args[]) throws JRException, dori.jasper.engine.JRException{
new myreport2().reportName();
}
}
------解决方案--------------------
空指针 有可能你的数据源的信息和对应的模板上的参数不一致 有缺失