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

Getting null pointer exception on fillReport


fwilliams

Recommended Posts

Hi all,

 

Would be very much appeciative if someone could point me in the right direction

 

try {

if (conn != null) {

File f = new File(reportFile);

InputStream is = new FileInputStream(f);

 

JasperReport jasperReport = JasperCompileManager.compileReport(

is);

 

jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);

 

}

} catch (JRException ejr) {

ejr.printStackTrace();

}catch (Exception __ex) {

__ex.printStackTrace();

}

 

it gives me the following exception :

java.lang.NullPointerException

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:161)

at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:119)

at net.sf.jasperreports.engine.util.JRSingletonCache.createInstance(JRSingletonCache.java:88)

at net.sf.jasperreports.engine.util.JRSingletonCache.getCachedInstance(JRSingletonCache.java:78)

at net.sf.jasperreports.engine.util.JRTextMeasurerUtil.getTextMeasurerFactory(JRTextMeasurerUtil.java:118)

at net.sf.jasperreports.engine.util.JRTextMeasurerUtil.createTextMeasurer(JRTextMeasurerUtil.java:103)

at net.sf.jasperreports.engine.util.JRTextMeasurerUtil.createTextMeasurer(JRTextMeasurerUtil.java:90)

 

Thanks in advance for any help

 

Fraser Williams

Link to comment
Share on other sites

  • Replies 12
  • Created
  • Last Reply

Top Posters In This Topic

As well I should note that the error is being thrown at the JasperFillManager.fillReport part of the code.

 

This is mind boggling as this has always worked for me in the past only when I upgraded iReport has this started to occure.

 

Thanks again - Fraser

Link to comment
Share on other sites

Thanks for your response. My classpath has no other versions of the jasperreports jars.

 

I have a directory where I have put the iReport program. I have put a small application in the same directory which offers a menu system for the user to view a report. The user double clicks the report and the report is supposed to show in the JRViewer however I am getting the error as described above. IReport works like a charm from the same folder so it puzzles me as to why my program doesn't. Hmmmm!

 

I code with Netbeans the jasperreports jars are referenced in the libraries and no other classpath information is specified.

 

Fraser

Link to comment
Share on other sites

  • 2 months later...

Hi all!

 

I get exactly the same problem with only one version of the JasperReports jar on the classpath... (the 2.0.5)

For information, is use iReport 2.0.2 and it works fine but not my application...

 

Did anybody find a solution ?

 

Thanks in advance !

JB

Link to comment
Share on other sites

Hi,

 

For information, I solved this problem modifying the default.jasperreports.properties file as follow :

 

Replace

Code:

#Default text measurer
net.sf.jasperreports.text.measurer.factory=default
net.sf.jasperreports.text.measurer.factory.default=net.sf.jasperreports.engine.fill.TextMeasurerFactory

 

by

Code:
[code]
#Text measurer (overridden because of a NullPointerException in JRClassLoader...)
net.sf.jasperreports.text.measurer.factory=net.sf.jasperreports.engine.fill.TextMeasurerFactory

 

I hope this will help...

JB

Link to comment
Share on other sites

  • 2 months later...

I got the same problem as this when moving from Jasper 2.0.1 to 3.0.0, and I tracked it down. To repeat, this is the stack trace:

 

Code:

java.lang.NullPointerException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:161)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:119)
at net.sf.jasperreports.engine.util.JRSingletonCache.createInstance(JRSingletonCache.java:88)
at net.sf.jasperreports.engine.util.JRSingletonCache.getCachedInstance(JRSingletonCache.java:78)
at net.sf.jasperreports.engine.util.JRTextMeasurerUtil.getTextMeasurerFactory(JRTextMeasurerUtil.java:118)
at net.sf.jasperreports.engine.util.JRTextMeasurerUtil.createTextMeasurer(JRTextMeasurerUtil.java:103)
at net.sf.jasperreports.engine.util.JRTextMeasurerUtil.createTextMeasurer(JRTextMeasurerUtil.java:90)
at net.sf.jasperreports.engine.fill.JRFillTextElement.createTextMeasurer(JRFillTextElement.java:115)
at net.sf.jasperreports.engine.fill.JRFillTextElement.ensureTextMeasurer(JRFillTextElement.java:122)
at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:972)
at net.sf.jasperreports.engine.fill.JRFillStaticText.prepare(JRFillStaticText.java:193)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:344)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:346)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:305)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillTitle(JRVerticalFiller.java:313)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:247)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:879)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:801)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)
at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:492)
at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:448)

 

I am not fluent with the Jasper source enough to propose a fix, but I now where the problem occurs. In net.sf.jasperreports.engine.util.JRTextMeasurerUtil line 86 there is this function:

Code:
[code]
public static JRTextMeasurer createTextMeasurer(JRCommonText text)
{
JRPropertiesHolder propertiesHolder =
text instanceof JRPropertiesHolder ? (JRPropertiesHolder) text : null;
return createTextMeasurer(text,
propertiesHolder);
}

As you can see, if the input is not an instance of JRPropertiesHolder then the function ends with a call to createTextMeasurer(text, null).

 

createTextMeasurer calls other functions to load a class based upon its second input parameter, and naturally this throws a NullPointerException.

Link to comment
Share on other sites

EsauCairn wrote:

I am not fluent with the Jasper source enough to propose a fix, but I now where the problem occurs. In net.sf.jasperreports.engine.util.JRTextMeasurerUtil line 86 there is this function:
Code:

public static JRTextMeasurer createTextMeasurer(JRCommonText text)
{
JRPropertiesHolder propertiesHolder =
text instanceof JRPropertiesHolder ? (JRPropertiesHolder) text : null;
return createTextMeasurer(text,
propertiesHolder);
}

As you can see, if the input is not an instance of JRPropertiesHolder then the function ends with a call to createTextMeasurer(text, null).

 

createTextMeasurer calls other functions to load a class based upon its second input parameter, and naturally this throws a NullPointerException.

 

createTextMeasurer() should work fine with a null propertiesHolder. If you trace the code further, you'll see that the propertiesHolder is used in calls to [url=http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/util/JRProperties.html#getProperties(net.sf.jasperreports.engine.JRPropertiesHolder,%20java.lang.String)]JRProperties.getProperties(JRPropertiesHolder, String). If propertiesHolder is null, the default JR properties would be used to determine the text measurer class name.

 

If you post a test case to reproduce this problem, we would investigate it and find what causes it.

 

Regards,

Lucian

Link to comment
Share on other sites

lucianc,

You were correct and I was wrong. I apologize for posting unhelpful data.

 

All I can see is that if you replace

net.sf.jasperreports.text.measurer.factory=default

net.sf.jasperreports.text.measurer.factory.default=net.sf.jasperreports.engine.fill.TextMeasurerFactory

 

with

net.sf.jasperreports.text.measurer.factory=net.sf.jasperreports.engine.fill.TextMeasurerFactory

The null pointer exception goes away.

 

The problem baffles me. To reproduce the problem, I simply need to run:

Code:

String path = getPath();
String fileName = getReportFileName();
Map parameters = new HashMap();
populate(parameters);

JasperCompileManager.compileReportToFile(path + filename + ".jrxml"«»);
JasperFillManager.fillReportToFile(path+filename+".jasper", parameters, new JREmptyDataSource());

 

It runs without errors with the change to the default.jasperreports.properties configuration file above, and gives the noted nullpointerexception otherwise.

 

I'll try to take another stab at this over the weekend, see if I can't lock it down. Thanks for your help.

Link to comment
Share on other sites

Link to comment
Share on other sites

I would prefer to wait to file the report until I can pinpoint the problem and possibly recommend a solution.

 

I took the jar file out of my project. Instead, I included the source code from Jasper 3.0.0 into my project, built it, and ran it. The bug did not appear. This is, naturally, puzzling. When the bug appears in the .jar, the stack trace line numbers match the source code line numbers exactly, so I consider the possibility that the official .jar has separate code from the source tree to be very small.

 

Next I am going to use the .jar and replace the affected class files with ones compiled from source one at a time to pinpoint the problem.

Link to comment
Share on other sites

  • 3 years later...

 hi,

 

I have tried to edit the default.jasperreports.prop in jasper.jar, but still got the NullPointer exceptions, such as:

java.lang.NullPointerException

at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)

at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:628)

at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:544)

 

What I am trying to do is: user jasper 3.5.3 with spring 3.0.2 on glassfish 2.1. 

 

The next line is causing the trouble:

jasperPrint = JasperFillManager.fillReport(myFile.getPath(),parameters, jasperDs);

 

All of these parameters are not null, and has valid and  good values in it.

 

Any ideas Guys?

 

thx

Link to comment
Share on other sites

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...