DOCX2JATS icon indicating copy to clipboard operation
DOCX2JATS copied to clipboard

Null pointer exception for figures

Open B5045438 opened this issue 6 years ago • 20 comments

The program stops conversion and throws a null pointer exception when using a Harvard references.

Full trace:

BUILD SUCCESSFUL Total time: 4 seconds

reference list has been found

Exception in thread "main" java.lang.NullPointerException at doc.transformation.xml.transformerFigures.transformerFiguresImpl(transformerFigures.java:75) at doc.transformation.xml.docIngestion.ingestionAndTransform(docIngestion.java:122) at doc.transformation.xml.docIngestion.main(docIngestion.java:52)

B5045438 avatar Jun 20 '18 11:06 B5045438

After testing with another file turns out that the issue is not related to the references.

B5045438 avatar Jun 20 '18 13:06 B5045438

This could be because of many reasons. Can you show a problematic DOCX file?

Vitaliy-1 avatar Jun 21 '18 17:06 Vitaliy-1

It is a part of the code that responsible for figure comments. Do you know Java? You can simply put this part of code into the try-cache block: https://github.com/Vitaliy-1/DOCX2JATS/blob/master/src/doc/transformation/xml/transformerFigures.java#L72-L78

If it helps, do the commit. Tell me if this is problematic for you.

Keep in mind that I'm not planning to continue this project as for next several months will be writing a new parser on PHP that can be integrated to OJS. This current parser relies on a side project (TEIC Stylesheets) and on that transformation stage much data are lost. As I see from now, it is better to write all from the scratch.

Vitaliy-1 avatar Jun 21 '18 19:06 Vitaliy-1

Here a link to the article that is causing the issue: article.docx

Good to see that a integrated solution is on its way, but I need a stopgap for now.

For the java bit, Looks like any easy modification I can for the figure comments, but couldn't manage to build a new jar file using javac as I got a build exception:

./docIngestion.java:34: error: package org.apache.tools.ant does not exist import org.apache.tools.ant.BuildException;

Which build settings did you use?

B5045438 avatar Jun 21 '18 20:06 B5045438

This is apache ant library. It should be include into the project.

Vitaliy-1 avatar Jun 21 '18 21:06 Vitaliy-1

Ok, I will look at the file

Vitaliy-1 avatar Jun 21 '18 21:06 Vitaliy-1

Any specific instructions on how to build it using ant?

B5045438 avatar Jun 22 '18 08:06 B5045438

@Vitaliy-1 So I have been trying to run an ant build but I couldn't find the build.xml file in the directory. Should I make one myself, if so what dependencies should I use?

B5045438 avatar Jun 29 '18 10:06 B5045438

Don't recommend to do anything in the build.xml managing those dependencies there was a headache for me, as I don't know ant build well :) Basically, if you using eclipse, it recommends you what libraries you are missing: ant-launcher.jar, ant.jar, and saxon9he.jar. Did you include all 3 in your classpath?

Vitaliy-1 avatar Jun 29 '18 12:06 Vitaliy-1

https://github.com/Vitaliy-1/DOCX2JATS/blob/master/stylesheets/docx/build-from.xml Ideally. this project should be converted to maven project and point all dependencies there...

Vitaliy-1 avatar Jun 29 '18 12:06 Vitaliy-1

@Vitaliy-1 I placed them in eclipse and did get the missing warnings for ant-launcher.jar, ant.jar, and saxon9he.jar. From where do I include them?

B5045438 avatar Jun 29 '18 14:06 B5045438

They are all available through maven. For example: https://mvnrepository.com/artifact/net.sf.saxon/saxon9he/9.4.0.4

Vitaliy-1 avatar Jun 29 '18 19:06 Vitaliy-1

The also can be download manually. if you are not familiar with maven. Saxon, for example, is available here: https://sourceforge.net/projects/saxon/files/

Vitaliy-1 avatar Jun 29 '18 19:06 Vitaliy-1

@Vitaliy-1 image

It is asking for a pattern and a pattern name, what should I put in here?

B5045438 avatar Jul 03 '18 08:07 B5045438

Not sure. And what you are trying to do?

Vitaliy-1 avatar Jul 03 '18 21:07 Vitaliy-1

The main method is inside docIngestion class. If you want to run it from IDE (to check the code before making a jar file) you can specify your input and output file paths here: https://github.com/Vitaliy-1/DOCX2JATS/blob/master/src/doc/transformation/xml/docIngestion.java#L46 and here: https://github.com/Vitaliy-1/DOCX2JATS/blob/master/src/doc/transformation/xml/docIngestion.java#L50

Vitaliy-1 avatar Jul 03 '18 21:07 Vitaliy-1

@Vitaliy-1 I'm trying to build the project to get the jar file to run the program not run it from the IDE.

B5045438 avatar Jul 04 '18 08:07 B5045438

I've only done this before in Eclipse: https://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/jarInEclipse.htm

Vitaliy-1 avatar Jul 04 '18 12:07 Vitaliy-1

@Vitaliy-1 Managed to get the jar, but there seems to be an issue with class path/definitions as it throws this when I try to run it:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException

Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.privateGetMethodRecursive(Unknown Source) at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod(Unknown Source) at sun.launcher.LauncherHelper.validateMainClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.BuildException at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 7 more

B5045438 avatar Jul 04 '18 13:07 B5045438

Java can't find ant library here. OK, I will rebuild the project as a Maven to ease the work with dependencies at the end of next week.

Vitaliy-1 avatar Jul 05 '18 17:07 Vitaliy-1