B4J Question jPOI clarifications

PatrikCavina

Active Member
Licensed User
Longtime User
Hi to all,
I tried to use jPOI library to manage word file.
In this case i want get specifics of page for resize columns table where i want insert images.
Problem comes when i try to get page specifics using "getBody" method.
B4X:
Private Sub Class_Globals
    Private fx As JFX
    Private Document As JavaObject
    Private table As JavaObject
End Sub

Public Sub Initialize
    Document.InitializeNewInstance("org.apache.poi.xwpf.usermodel.XWPFDocument",Null)
End Sub

Sub getPageSize As Object
    Dim o As Object = Document.RunMethodJO("getDocument",Null).RunMethodJO("getBody",Null).RunMethodJO("getSectPr",Null)
    Return o
End Sub

Public Sub CreateTable(row As Int, columns As Int)
    table = Document.RunMethod("createTable", Array(row,columns))
End Sub

Sub SaveDocument(doc As JavaObject, Dir As String, FileName As String)
    Dim out As OutputStream = File.OpenOutput(Dir, FileName, False)
    doc.RunMethod("write", Array(out))
    out.Close
End Sub

Exeption:
B4X:
Waiting for debugger to connect...
Program started.
Cannot get methods of class: org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.CTDocument1Impl, disabling cache.
Error occurred on line: 13
java.lang.NullPointerException
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:343)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:614)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:61)
    at b4j.example.word._getpagesize(word.java:57)
    at b4j.example.main._appstart(main.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:614)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at b4j.example.main.start(main.java:38)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
I already insert all the libraries and jar file in Additional libraries folder and in main module I set #AdditionalJar: poi-3.12-20150511.
I can't understand which is the problem
 

PatrikCavina

Active Member
Licensed User
Longtime User
Unfortunately, it's just a sketch of a project that I can not continue now. All developments will be posted on the forum in case i continue
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…