dbarra / xdocreport

Automatically exported from code.google.com/p/xdocreport
1 stars 0 forks source link

Null ExceptionError when adding an image #233

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Create the Inputstream and instanciate IXDcoReport:
InputStream in= new FileInputStream(new File(sFileName));
IXDocReport report = 
XDocReportRegistry.getRegistry().loadReport(in,TemplateEngineKind.Velocity);
IContext context = report.createContext();
2.Add the image
FieldsMetadata metadata = new FieldsMetadata();
metadata.setEvaluateEngineOnlyForFields(true);
metadata.addFieldAsImage("img"); 
report.setFieldsMetadata(metadata); 
String sImageFile = System.getProperty("java.io.tmpdir")+"output.png";
IImageProvider imgToInclude = new FileImageProvider(new File(sImageFile), true);
context.put("img", imgToInclude);

3.OutputStream out = new FileOutputStream(new File(sTargetFile));
report.process(context, out);
out.close();

What is the expected output? What do you see instead?
The image added.
But I receive the error :
org.apache.velocity.exception.MethodInvocationException: Invocation of method 
'getWidth' in  class 
fr.opensagres.xdocreport.document.docx.images.DocxImageRegistry threw exception 
java.lang.NullPointerException at 
fr.opensagres.xdocreport.document.docx.DocxReport@4666b6!word/document.xml[line 
1, column 75773]
    at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:243)
    at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:187)
    at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
    at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:369)
    at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
    at org.apache.velocity.Template.merge(Template.java:356)
    at org.apache.velocity.Template.merge(Template.java:260)
    at fr.opensagres.xdocreport.template.velocity.internal.VelocityTemplateEngine.processWithCache(VelocityTemplateEngine.java:99)
    at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:111)
    at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:83)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.processTemplateEngine(AbstractXDocReport.java:772)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.process(AbstractXDocReport.java:518)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.process(AbstractXDocReport.java:484)
    at com.airbus.tamed.ui.actions.ReportTemplateDialog$1.widgetSelected(ReportTemplateDialog.java:313)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at com.airbus.tamed.ui.actions.ReportTemplate.run(ReportTemplate.java:43)
    at com.airbus.tamed.ui.editors.TamedMultiPageEditor$1.widgetSelected(TamedMultiPageEditor.java:545)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at com.airbus.tamed.ui.TamedApplication.start(TamedApplication.java:141)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Caused by: java.lang.NullPointerException
    at fr.opensagres.xdocreport.document.images.AbstractImageRegistry.getWidth(AbstractImageRegistry.java:261)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:395)
    at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:384)
    at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:173) 

What version of the product are you using? On what operating system?
V1.0.0 on Windows 7 Pro.

Please provide any additional information below.
The process work if update only fields. Since I add an image, it fails.
What I saw is that the height and widht attribute are equals to null in the 
imgToInclude object. Even if I put values with setWidth and Heifht methods, it 
still fails.

Coudl you please helps me.
Knd Regards,
Fouad

Original issue reported on code.google.com by FBenan...@gmail.com on 14 Mar 2013 at 1:46

GoogleCodeExporter commented 8 years ago
Hi Fouad,

1) try to remove metadata.setEvaluateEngineOnlyForFields(true); 
When I have done that, it was just for mergefield I think.

2) check your bookmark is named with "img" name.

3) check sImageFile file exists.

If you have again problems after your checks, please attach your docx, image 
and Java code which causes your problem.

Regards Angelo

Original comment by angelo.z...@gmail.com on 14 Mar 2013 at 2:03

GoogleCodeExporter commented 8 years ago
I close this issue because I have none answer.

Original comment by angelo.z...@gmail.com on 18 Feb 2014 at 2:19