B4J Question Error opening word doc -

focus330

Member
Licensed User
Longtime User
Hello

I'm trying to open a word doc file with this code:
B4X:
Sub OpenDocx As JavaObject
    Dim in As InputStream = File.OpenInput(dir, filename)
    Dim document As JavaObject
    Try
    document.InitializeNewInstance("org.apache.poi xwpf.usermodel.XWPFDocument", Array(in))
    Return document
    Catch
        fx.Msgbox(Null,LastException.Message,"Error")
        Log(LastException.Message)
    End Try
End Sub

I Have this error: java.lang.ClassNotFoundException: org.apache$poi xwpf$usermodel$XWPFDocument

I'm using jdk 11.0.1 but i have the same error using 1.8.0_141
Libraries JPOI ( 5.0 ) and XLUtils ( 1.14) are checked. B4j version is 9.0
I also add the dependencies for poi 5.0 into libraries and also into addlibraries.

Searching with browser I find that may be ooxml jar not updated. If yes how to repair ?

What can I do ?
Thanks for your help.

Regards
S.Viola
 
Last edited:

focus330

Member
Licensed User
Longtime User
What a mistake ! Thanks.
But now, I have another error
Two paragraphs:
The first begin with :

java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:91)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

The second:
Caused by: java.lang.NoSuchMethodError: org.apache.poi.util.IOUtils.peekFirstNBytes(Ljava/io/InputStream;I)[B
at org.apache.poi.poifs.filesystem.FileMagic.valueOf(FileMagic.java:209)
at org.apache.poi.openxml4j.opc.internal.ZipHelper.verifyZipHeader(ZipHelper.java:143)
at org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipStream(ZipHelper.java:175)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:104)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:312)
at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:47)
at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:123)
... 82 more
It seems that the documents ( I tried more than one ) are not readable. I try rewriting with word in version word 95, word 6.0 but the error is the same.
Note that a test function with WebView with the same docs was positive until yesterday in the morning. Yesterday I tried installing Office last edition to see if problems with poi will be resolved. Now I uninstall office.
Have Ito declare some jar ? Attached the complete log
 

Attachments

  • log.txt
    7.1 KB · Views: 128
Upvote 0

focus330

Member
Licensed User
Longtime User
Also with docx I have the same error. Now I try a small project as suggested. See you later. Thanks
 
Upvote 0

focus330

Member
Licensed User
Longtime User
Yes. With a new project It works. Open docx and also save function. Now I have to add a print function and then 'copy' to my master program.
Thanks.
 
Upvote 0

focus330

Member
Licensed User
Longtime User
For information:
The documents I had to use are 'doc' made with Windows95. Rewriting into a 'docs' version they lost tags , fields or union, formatting and others. Not only but someone of them becomes corrupted.
Then it seems to me that poi to populate fields isn't the best solution also because I don't know how to print them.
Then I have to decide what is better:
1 use Tibco reports replacing doc models Good solution but I have to build 15 reports.
2 generate from the app an excel file with data (or at least an Mdb but I have to verify if B4j supports access drivers ) to use externally printing union. Very simple but user has to work as now and I have not a complete control from the app.

Best regards
 
Upvote 0
Top