0

I have existing working project on java. I need to change template ".docx" document. When I'm trying to create a new WordDocument with another ".docx" document, I get an exception. What can be wrong? Sorry for my english.

There is a my code:

`WordDocument document = new WordDocument(templatesDirectory + "order.docx");`

There is a stacktrace:

`java.lang.NumberFormatException: For input string: "11340.0"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at com.independentsoft.office.word.tables.Width.a(Unknown Source)
at com.independentsoft.office.word.tables.Width.<init>(Unknown Source)
at com.independentsoft.office.word.tables.TableProperties.a(Unknown Source)
at com.independentsoft.office.word.tables.TableProperties.<init>(Unknown Source)
at com.independentsoft.office.word.tables.Table.a(Unknown Source)
at com.independentsoft.office.word.tables.Table.<init>(Unknown Source)
at com.independentsoft.office.word.Body.a(Unknown Source)
at com.independentsoft.office.word.Body.<init>(Unknown Source)
at com.independentsoft.office.word.WordDocument.a(Unknown Source)
at com.independentsoft.office.word.WordDocument.openImplementation(Unknown Source)
at com.independentsoft.office.word.WordDocument.open(Unknown Source)
at com.independentsoft.office.word.WordDocument.open(Unknown Source)
at com.independentsoft.office.word.WordDocument.<init>(Unknown Source)`
KseniyaK
  • 11
  • 2
  • 1

2 Answers2

1

The problem was solved! The problem was in a file, it was saved with google docs. Now I resave it with MSOffice, and so code works!

KseniyaK
  • 11
  • 2
  • 1
0

You should check out the message you get in the Exception: it says

java.lang.NumberFormatException: For input string: "11340.0"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)

Somewhere in your code you are trying to generate an Integer from a String that cannot be converted to an Integer.
In your case: 11340.0: although the mathematical value is an integer value, Java understands that it is a Float or a Double because of the ending .0 and raises an exception.

Try to find where that convertion occurs from and see if you can catch / manage the exception.

avi.elkharrat
  • 6,100
  • 6
  • 41
  • 47
  • Thanks for your answer! But there is problem not in my code, I think. This exception was thrown when I change template .docx file. May be problem in this file(may be table width), but I don't know, where exactly and what should i do to fix it: "at com.independentsoft.office.word.tables.Width.a(Unknown Source)" – KseniyaK May 30 '18 at 17:43