0

It may be obvious but can someone help. The project compiles fine the error occurs at run-time:

12-02 06:56:36.871: I/dalvikvm(1121): Could not find method org.docx4j.openpackaging.packages.WordprocessingMLPackage.createPackage, 
referenced from method com.example.datadevheadlines.DeclerationCreator.makeIt

12-02 06:56:36.871: W/dalvikvm(1121): VFY: unable to resolve static method 9664: Lorg/docx4j/openpackaging/packages/WordprocessingMLPackage;.createPackage ()
Lorg/docx4j/openpackaging/packages/WordprocessingMLPackage;

12-02 06:56:36.881: D/dalvikvm(1121): VFY: replacing opcode 0x71 at 0x002c

12-02 06:56:36.881: W/dalvikvm(1121): VFY: unable to resolve exception class 1281 (Lorg/docx4j/openpackaging/exceptions/InvalidFormatException;)

12-02 06:56:36.881: W/dalvikvm(1121): VFY: unable to find exception handler at addr 0x42

12-02 06:56:36.881: W/dalvikvm(1121): VFY:  rejected Lcom/example/datadevheadlines/DeclerationCreator;.makeIt (Landroid/view/View;)V

12-02 06:56:36.921: W/dalvikvm(1121): VFY:  rejecting opcode 0x0d at 0x0042

12-02 06:56:36.921: W/dalvikvm(1121): VFY:  rejected Lcom/example/datadevheadlines/DeclerationCreator;.makeIt (Landroid/view/View;)V

12-02 06:56:36.921: W/dalvikvm(1121): Verifier rejected class Lcom/example/datadevheadlines/DeclerationCreator;

12-02 06:56:36.921: W/dalvikvm(1121): Class init failed in newInstance call (Lcom/example/datadevheadlines/DeclerationCreator;)

All docx4j and dependency jars are all in a user library.

I think I have solved the error by copying the jars into the /lib folder now I get the following error:

Conversion to Dalvik format failed with error 1. The code I am attempting to run is:

        WordprocessingMLPackage wordMLPackage = null;
    try {
        wordMLPackage = WordprocessingMLPackage.createPackage();
    } catch (InvalidFormatException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    wordMLPackage.getMainDocumentPart().addParagraphOfText("Hello Word!");
    try {
        String path = Environment.getExternalStorageDirectory().toString() + "/HelloWord1.docx";
        File file = new File(path);
        try {
            file.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }           
        wordMLPackage.save(file);
    } catch (Docx4JException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

UPDATE!!!!!!!!!!!!

I gave up on doc4jx and didn't want to pay for itext and so used PrintedPdfDocument as the document I want is a fixed template it is sufficient enough for my needs. Anything dynamic be a problem. Basically used a layout frame as a canvas and positioned all my texts and headings as relevant and then printed it to a pdf.

A problem I found was that having the text at a visible size meant on a A4 pdf one word would cover a big chunk of the page so I had to make the text 4sp and 7sp so that it would fit perfectly and had to have a centeralised layout frame that didn't fill the activity frame.

Anybody know a easier way of scaling the layout to an A4 size without having to shrink it into a zoomed out preview?

Gulfaran
  • 91
  • 5

1 Answers1

0

Hmm, obviously something is wrong with the dependencies. How did you include everything? Maybe try it with Maven, then there should be everything included.

Are all imports correct? I found that some class names are used in different packages, maybe you picked the wrong one somewhere? Do you have a code snippet for us?

  • I downloaded the zip from http://www.docx4java.org/downloads.html unzipped the contents and added them to the build path of the project by creating a user library called docx4j. I have attempted to use maven however when I am adding the software into eclipse using the help "Install new software" option it says files are missing. I'll get the code onto here soon – Gulfaran Dec 12 '14 at 14:04
  • I got it right with this tutorial: http://www.docx4java.org/blog/2011/10/hello-maven-central/ – Matthias Nicklisch Dec 12 '14 at 14:08
  • Also here is the part from the pom.xml: org.docx4j docx4j 3.2.1 – Matthias Nicklisch Dec 12 '14 at 14:08
  • When I try installing maven I get this: Cannot complete the install because one or more required items could not be found. Software being installed: m2e - slf4j over logback logging (Optional) 1.5.0.20140606-0033 (org.eclipse.m2e.logback.feature.feature.group 1.5.0.20140606-0033) – Gulfaran Dec 12 '14 at 14:21
  • See further http://www.docx4java.org/blog/2012/05/jaxb-can-be-made-to-run-on-android/ – JasonPlutext Dec 12 '14 at 19:23
  • sorry for not getting back to you on what has been going on. I wasnt able to get it to work so I kinda abandoned it and used the print function that android have introduced instead. Really appreciate the help you provided. – Gulfaran Mar 28 '15 at 12:20