B4J Question [ABM for Dummies] (Solved) Problem using NextReports and ABMPdfViewer

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
I am trying to advance on my own in the generation of reports from the web app.
But I can not get past this point. When you reach the point where the report is launched in the log viewer, the following appears:

B4X:
    Dim inputlist As List
    Dim inlocation,repin, repout, reptype, driverclass, url As String
    '
    'Location of the *.report file and any necessary images
    inlocation=File.DirApp & filesep & "reports" 'For this demo the report is stored in the Objects/reports directory. You can specify any other directory.
    'name of report created by NextReports.
    repin="Usuarios2.0" ' Report specified: Report_name.report - No need for the .report extension
    '
    'Output file specification
    repout="MYOUTPUT" 'name of output report
    reptype="PDF"  ' Available options: CSV, TXT, XLS, XML, PDF, HTML or RTF. File type must be in CAPITALS.
    'Output file will be MYOUTPUT.RTF. Output file (and any necessary images) will be stored in your application directory
    '    logs the location of the report file
    LogDebug("Location = "&inlocation)
    'replace this by your database driver class name
    driverclass="com.mysql.jdbc.Driver"            '    driver class for Mysql
    '
    'replace this by applicable url for your database
    'I use IP instead of server name. For some reason, in my tests with SQL SERVER, when I used server name, it would not not work on MACs
    'jdbc:mysql://localhost:3306/HerongDB?user=Herong&password=TopSecret
    url="jdbc:mysql://localhost/harris?user=root&password=xxxxxx"
 
    'Initialize input list and add necessary arguments in the order shown below
    inputlist.initialize
    inputlist.Add(inlocation)
    inputlist.add(repin)
    inputlist.add(repout)
    inputlist.add(reptype)
    inputlist.add(driverclass)
    inputlist.add(url)
    Try
        'Run the report and export the output report file
        repexec.reportPrepAndRun(inputlist)
    Catch
        LogDebug("Error: Loading Reports : " & LastException.Message)
    End Try

B4X:
    java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at ro.nextreports.engine.util.ReportUtil.<clinit>(ReportUtil.java:95)
    at ro.nextreports.integration.ReportSupport.loadReport(ReportSupport.java:30)
    at ro.nextreports.integration.ReportExec.reportPrepAndRun(ReportExec.java:86)
    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:497)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:657)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    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 com.ab.template.reportpage._run_report(reportpage.java:89)
    at com.ab.template.reportpage._btnrun_clicked(reportpage.java:80)
    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:497)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:482)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:437)
    at com.ab.template.reportpage._page_parseevent(reportpage.java:1372)
    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:497)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    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 anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketModule.java:126)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:114)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:148)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:303)
    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:497)
    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 anywheresoftware.b4j.object.JServlet.createInstance(JServlet.java:65)
    at anywheresoftware.b4j.object.BackgroundWorkersManager$1.run(BackgroundWorkersManager.java:21)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:114)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:148)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:303)
    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:497)
    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 com.ab.template.main.main(main.java:29)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 76 more
Ha ocurrido un error en la línea: 711
java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:61)
    at com.ab.template.reportpage._run_report(reportpage.java:89)
    at com.ab.template.reportpage._btnrun_clicked(reportpage.java:80)
    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:497)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:482)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:437)
    at com.ab.template.reportpage._page_parseevent(reportpage.java:1372)
    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:497)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    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 anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketModule.java:126)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:114)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:148)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:303)
    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:497)
    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 anywheresoftware.b4j.object.JServlet.createInstance(JServlet.java:65)
    at anywheresoftware.b4j.object.BackgroundWorkersManager$1.run(BackgroundWorkersManager.java:21)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:114)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:148)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:303)
    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:497)
    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 com.ab.template.main.main(main.java:29)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at ro.nextreports.engine.util.ReportUtil.<clinit>(ReportUtil.java:95)
    at ro.nextreports.integration.ReportSupport.loadReport(ReportSupport.java:30)
    at ro.nextreports.integration.ReportExec.reportPrepAndRun(ReportExec.java:86)
    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:497)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:657)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    ... 62 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 76 more
Error: Loading Reports : java.lang.Exception: java.lang.Exception: array not expected...
An error occurred:
(Line: 0) End Sub
java.lang.Exception: array not expected...
An error occurred:
(Line: 0) End Sub
java.lang.RuntimeException: Unexpected value.
 

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
You probably better remove the [ABMaterial] prefix from the subject to get more responses as this has nothing to do with ABM itself.
You probably better remove the [ABMaterial] prefix from the subject to get more responses as this has nothing to do with ABM itself.
In the end I will leave the title the same, since the example I have prepared is specific to the ABMaterial, since when trying to show the result in an ABMPdfViewer I found problems with the absolute and relative paths.
 
Upvote 0

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
To solve the first part of the problem, I had to add a few more #AditionalJar that at first I thought would not be necessary.
I currently have all these added:
B4X:
'Do not forget to add jNxtReportsB4J in the B4J IDE Libraries tab
      #AdditionalJar: jNxtReportsB4J
'Download these jar files to the B4J Libraries folder
'All these jar files are available from http://www.next-reports.com/download.html
#AdditionalJar: nextreports-engine-9.1
     #AdditionalJar: commons-jexl-2.1.1
     #AdditionalJar: commons-logging-1.1.1
     #AdditionalJar: itext-2.1.7
     #AdditionalJar: itext-rtf-2.1.7
     #AdditionalJar: itextpdf-5.0.6
     #AdditionalJar: xstream-1.3.1
     #AdditionalJar: xstream-1.4.7
     #AdditionalJar: poi-3.7

Then I came across the problem that when trying to do the tests in debug mode, putting breakpoints caused other errors. With which I think it is advisable to use log () whenever we test things with FastReport.

And finally I found that the FastReports allow working with absolute paths, while the ABMPdfViewer seems to only work with relative paths.
I give you an example of how I let it finally work:
B4X:
Dim inputlist As List
Dim inlocation, repin, repout, pathrepout, reptype, driverclass, url As String
'
'Location of the * .report file and any necessary images
inlocation = File.DirApp & filesep & "reports" 'For this demo the report is stored in the Objects / reports directory. You can specify any other directory.
'name of report created by NextReports.
repin = "Users2.0" 'Report specified: Report_name.report - No need for the .report extension
'
'Path for Output file
pathrepout = "www \ template \ PDF \"
'Output file specification
repout = "MYOUTPUT" 'name of output report
reptype = "PDF" 'Available options: CSV, TXT, XLS, XML, PDF, HTML or RTF. File type must be in CAPITALS.
'Output file will be MYOUTPUT.RTF. Output file (and any necessary images) will be stored in your application directory
'logs the location of the report file
LogDebug ("Location =" & inlocation)
'replace this by your database driver class name
driverclass = "com.mysql.jdbc.Driver" 'driver class for Mysql
'
'replace this by applicable url for your database
'I use IP instead of server name. For some reason, in my tests with SQL SERVER, when I used server name, it would not work on MACs
'jdbc: mysql: // localhost: 3306 / HerongDB? user = Herong & password = TopSecret
url = "jdbc: mysql: // localhost / harris? user = root & password = usbw"
'DBM.InitializeMySQL ("jdbc: mysql: // localhost / harris? CharacterEncoding = utf8", "root", "usbw", 100)
'Initialize input list and add necessary arguments in the order shown below
inputlist.initialize
inputlist.Add (inlocation)
inputlist.add (repin)
inputlist.add (pathrepout & repout)
inputlist.add (reptype)
inputlist.add (driverclass)
inputlist.add (url)
 
'Now add your parameters - if any
'First, the parameter name - as it was defined in NextReports ie.
'add compare field in Report Designer $ {surname}
'Then add your parameter value - see examples below ...
'
'inputlist.add ("surname")
'inputlist.add ("xxxxx")
'
'for dates use date from DatePicker inputs on the B4j UI
'
'Dim t As Long
''
't = dpDateFrom.DateTicks
'inputlist.add ("start_date")
'inputlist.add (TicksToDate (t))
''
't = dpDateTo.DateTicks
'inputlist.add ("end_date")
'inputlist.add (TicksToDate (t))
'
'you can add as many parameters as necessary
'
Try
'Run the report and export the output report file
repexec.reportPrepAndRun (inputlist)
Catch
LogDebug ("Error: Loading Reports:" & LastException.Message)
End Try
'Show the output report file
Pdf.SetDocument (PdfPath & repout & "." & Reptype.ToLowerCase)
Pdf.Refresh
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Great! You figured this out on your own.
Lesson 6 shows exactly what you did - and more...

Like you discovered, Including NR isn't that difficult when you understand what is required - where and why...
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
You probably better remove the [ABMaterial] prefix from the subject to get more responses as this has nothing to do with ABM itself.

Or - more definitively - ABM for Dummies...
 
Upvote 0

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
Great! You figured this out on your own.
Lesson 6 shows exactly what you did - and more...

Like you discovered, Including NR isn't that difficult when you understand what is required - where and why...

I've got a problem with the structure of my users table trying lesson 6:

B4X:
[SIZE=6][B]users[/B][/SIZE]
[B]Columna[/B] [B]Tipo[/B] [B]Nulo[/B] [B]Predeterminado[/B] [B]Comentarios[/B]
UserID int(11) No  
UserName varchar(255) Sí  [I]NULL[/I]
UserLogin varchar(255) Sí  [I]NULL[/I]
UserPassword varchar(100) Sí  [I]NULL[/I]
UserType int(11) Sí  [I]NULL[/I]
UserActive int(11) Sí  [I]NULL[/I]
UserRows int(11) No  
comp_id int(11) No  
Usertz int(11) Sí  [I]NULL[/I]
s1 mediumtext Sí  [I]NULL[/I]
s2 mediumtext Sí  [I]NULL[/I]
s3 mediumtext Sí  [I]NULL[/I]

Exception obtained:

B4X:
ro.nextreports.engine.ReportRunnerException: ro.nextreports.engine.ReportRunnerException: ro.nextreports.engine.queryexec.QueryException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'users.pic' in 'field list'
 
Last edited:
Upvote 0
Top