Convert doc to pdf in android, Unable to execute dex

I am converting a doc file to pdf format in android using the following libraries,

  • IText-1.4.8.jar
  • poi-3.0-FINAL.jar
  • poi-notepad-3,2-FINAL.jar

here is my sample code

package com.example.converter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import android.content.Context; import android.os.Environment; import android.widget.LinearLayout; import com.lowagie.text.Document; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.hwpf.usermodel.Range; import org.apache.poi.poifs.filesystem.POIFSFileSystem; public class TestCon extends LinearLayout { FileInputStream infile; private static String FILE = Environment.getExternalStorageDirectory() + "/MyReport.pdf"; public TestCon(Context context) { super(context); my_method(context); } public void my_method(Context context) { POIFSFileSystem fs = null; Document document = new Document(); try { infile = (FileInputStream) context.getApplicationContext().getAssets().open("test.doc"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { System.out.println("Starting the test"); fs = new POIFSFileSystem(infile); HWPFDocument doc = new HWPFDocument(fs); WordExtractor we = new WordExtractor(doc); OutputStream file = new FileOutputStream(FILE); PdfWriter writer = PdfWriter.getInstance(document, file); Range range = doc.getRange(); document.open(); writer.setPageEmpty(true); document.newPage(); writer.setPageEmpty(true); String[] paragraphs = we.getParagraphText(); for (int i = 0; i < paragraphs.length; i++) { org.apache.poi.hwpf.usermodel.Paragraph pr = range .getParagraph(i); // CharacterRun run = pr.getCharacterRun(i); // run.setBold(true); // run.setCapitalized(true); // run.setItalic(true); paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", ""); System.out.println("Length:" + paragraphs[i].length()); System.out.println("Paragraph" + i + ": " + paragraphs[i].toString()); // add the paragraph to the document document.add(new Paragraph(paragraphs[i])); } System.out.println("Document testing completed"); } catch (Exception e) { System.out.println("Exception during test"); e.printStackTrace(); } finally { // close the document document.close(); } } 

}

but i get this error

 [2013-05-10 12:39:12 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/apache/poi/generator/FieldIterator; [2013-05-10 12:39:12 - converter] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/apache/poi/generator/FieldIterator; 

I uninstalled my android-v4.jar support. from the lib a / c folder to answer this answer, answer about the error , but I still get the same error :(

Please help me solve this problem. Anyone who has converted the document to PDF, share your code.

I will be very grateful:)

Yours faithfully

+4
source share
1 answer

The problem is that you include something twice or more:

 Multiple dex files define Lorg/apache/poi/generator/FieldIterator 

View your build path for duplicate libraries.

Also, as soon as this is resolved, you may have to add this line to the project.properties file: dex.force.jumbo = true

This will allow you to solve the problem with the problem of limiting 65535 methods for some time.

+1
source

Source: https://habr.com/ru/post/1480063/


All Articles