Jump to content
We've recently updated our Privacy Statement, available here ×

Applet Error NullPointerException in JR 3.0.0


mankari

Recommended Posts

Hello

I have a problem with Displaying JViewer in Applet

I don't know the cause but I am really blocked the above,Because the Applet she really work in Eclipse Java Applet but from my Html page i have the under Error

 

I'm working with JasperReports 3.0.0 and IReport 3.0.0.

 

Can anybody help me?

 

I Wait your answers

 

Thanks, MANKARI

 

the console display this Error:

Code:

7 juil. 2008 01:01:35 org.apache.commons.beanutils.MethodUtils getMatchingAccessibleMethod
WARNING: Current Security Manager restricts use of workarounds for reflection bugs in pre-1.4 JVMs.
java.lang.NullPointerException
at java.io.File.<init>(Unknown Source)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:155)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:219)
at AppletPrint.rapport(AppletPrint.java:109)
at AppletPrint.init(AppletPrint.java:50)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

 

Applet Code

 

Code:
[code]


import java.applet.Applet;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JInternalFrame;

import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.util.*;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.*;
import net.sf.jasperreports.view.JasperViewer;
import java.awt.BorderLayout;

public class AppletPrint extends Applet {

private static final long serialVersionUID = 1L;
private JInternalFrame jInternalFrame = null;
private JPanel jContentPane = null;
private Connection con= null; // @jve:decl-index=0:
/**
* This is the default constructor
*/
public AppletPrint() {
super();
}

/**
* This method initializes this
*
* @return void
*/
public void init() {

this.setLayout(null);
this.setSize(950, 516);
this.getConnection();

this.rapport();
this.add(getJInternalFrame(), null);

//jInternalFrame.getContentPane().add(chart);
//jInternalFrame.setVisible(true);
}


/**
* This method initializes jInternalFrame
*
* @return javax.swing.JInternalFrame
*/
private JInternalFrame getJInternalFrame() {
if (jInternalFrame == null) {
jInternalFrame = new JInternalFrame();
jInternalFrame.setBounds(new Rectangle(0, 0, 950, 500));
jInternalFrame.setContentPane(getJContentPane());
}
return jInternalFrame;
}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
}
return jContentPane;
}


private Connection getConnection() {
if (con == null) {
try{
Class.forName("com.mysql.jdbc.Driver"«»);
}
catch(ClassNotFoundException e)
{
System.err.println("impossible de charger le pilote oraclethin"«»);
}
try {
String DBurl = "jdbc:mysql://localhost:3306/chartdonnee";
con = DriverManager.getConnection(DBurl,"root","passroot"«»);
} catch (SQLException e) {
System.err.println("Connection à la base de données impossible"«»);}
}
return con;
}

private void rapport()
{
try
{//JasperDesign jasperDesign = JRXmlLoader.load("C:\JavaApplication1\dist\src\test.jrxml"«»);
JasperDesign jasperDesign = JRXmlLoader.load("C:\TestAppletReport\classic.jrxml"«»);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
// - Paramètres à envoyer au rapport
Map<String, String> params = new HashMap<String, String>();
params.put("reportTitle", "Rapport Profile des Employés"«»);
params.put("author", "Mankari abdeljawad"«»);
params.put("startDate", (new java.util.Date()).toString());
// - Execution du rapport
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params,con);

// - Création du rapport au format HTML
//JasperExportManager.exportReportToHtmlFile(jasperPrint,"C:\test.html"«»);
JasperViewer.viewReport(jasperPrint);
} catch (JRException e) {
e.printStackTrace();
}
}

} // @jve:decl-index=0:visual-constraint="9,-108"

 

Web Page call the Applet

 

Code:
[code]

<html>
<head>
<title>
Page de test d'Applet
</title>
</head>
<body>

<br><br><br>
<applet code= "AppletPrint.class"
archive="lib/commons-beanutils-1.7.jar,lib/swing-layout-1.0.jar,lib/commons-collections-2.1.jar,lib/commons-digester-1.7.jar,lib/commons-logging-1.0.2.jar,lib/commons-logging-api-1.0.2.jar,lib/jasperreports-3.0.0.jar,lib/mysql-connector-java-3.0.17-ga-bin.jar,AppletReport.jar,lib/jfreechart-1.0.10.jar,lib/jcommon-1.0.13.jar"
width="950" height="550">
Votre navigateur n'est pas compatible java.
</applet>

</body>
</html>

 

My Sample Report

Code:
[code]
<?xml version="1.0"?>
<!DOCTYPE jasperReport
PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="HelloReportWorld">
<detail>
<band height="200">
<staticText>
<reportElement x="0" y="0" width="500" height="20"/>
<text><![CDATA[Hello Report World!]]></text>
</staticText>
</band>
</detail>
</jasperReport>
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...