B4J Question #additionaljar, Confused

codie01

Active Member
Licensed User
Longtime User
I am trying to integrate a jar as an external library into my ABMaterial app to talk to cups print server on linux.

I really cannot get my head around this and ask for help. Here is my code so far.

B4X:
    Dim printerlist As List
    Dim cups As JavaObject
    cups.InitializeStatic("org.cups4j.CupsClient")
    printerlist = cups.RunMethod("getPrinters", Null )
    Log( printerlist )

The first issue is i can not set the ip and user under CupsClient. As an example could someone please show some code to 1) intialise the object and 2) run the "getPrinters" method.

The link to the API or Jar is http://cups4j.org/api/docs/api/

The doc I have pasted below.

Much Thanks in advance.
 
Last edited by a moderator:

codie01

Active Member
Licensed User
Longtime User
Thanks Erel,
I have changed the code as per following and it throws the following error:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

B4X:
cups.InitializeNewInstance("org.cups4j.CupsClient",Array("000.000.000.000", 631, "root"))
Log(cups.RunMethod("getPrinters", Null))
 
Upvote 0

codie01

Active Member
Licensed User
Longtime User
Thanks Again Erel,

As a background I am doing this from within ABMaterial.

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:188)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
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.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at b4j.example.printgenero._getprinters(printgenero.java:172)
at b4j.example.printgenero._section0(printgenero.java:308)
at b4j.example.printgenero._connectpage(printgenero.java:150)
at b4j.example.printgenero._websocket_connected(printgenero.java:447)
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)
... 7 more
Caused by: java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
at org.cups4j.CupsClient.getPrinters(CupsClient.java:107)
... 21 more
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 22 more
 
Upvote 0

codie01

Active Member
Licensed User
Longtime User
Erel you awesome. Many thanks.

There was a jar missing as you stated. There are two required as follows:

#AdditionalJar: cups4j-0.6.4
#AdditionalJar: cups4j.runnable-0.6.4

And the code:

B4X:
cups.InitializeNewInstance("org.cups4j.CupsClient",Array("000.000.000.000", 631, "root"))
Log(cups.RunMethod("getPrinters", Null))

The log result is: []

At a guess I would say it found no printers, is this right?

Many thanks, I really don't know how you do this so tirelessly, impressive!
 
Upvote 0
Top