B4J Question How to use a Server Handler written in a library in my code

FrostCodes

Active Member
Licensed User
Hi coders, i wrote a library and i wrapped Jserver inside and wrote my server handlers also there. I tried using this library inside a cli program and to my surprise i got error. Please any suggestion?

cuppifyrouter is my server handler inside the library.

Waiting for debugger to connect...
Program started.
2018-11-28 13:42:58.737:INFO::main: Logging initialized @1288ms to org.eclipse.jetty.util.log.StdErrLog
Error occurred on line: 32 (Main)
java.lang.ClassNotFoundException: b4j.example.cuppifyrouter
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:165)
at Punchline.Tech.Cuppify.cuppify._start(cuppify.java:316)
at b4j.example.main._appstart(main.java:125)
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:628)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
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:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.main(main.java:29)
Program terminated (StartMessageLoop was not called).
 

FrostCodes

Active Member
Licensed User
Thanks , the above did solve my problem but created another.
Inside my library the handler: CuppifyRouter is not able to call an external sub inside a code module using call sub. I tried adding the external package name like

punchline.myapi.MyModule.MyExternalSub this doesn't work also ..

B4X:
If SubExists("punchline.myapi.MyModule", "MyExternalSub") Then

            CallSub3("punchline.myapi.MyModule", "MyExternalSub", "My First Paremeter", "My Second Parameter")
  
        End If


Please any way about this ?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Shouldn't the first parameter of SubExists be an Object and not a String?

B4X:
Dim m As SomeClassModule
' otherCodeModule is a code module in project
…
' class module
If SubExists(m,"someMethod") then
…
' code module
if SubExists(otherCodeModule,"anotherMethod") then 
...
 
Upvote 0

FrostCodes

Active Member
Licensed User
Shouldn't the first parameter of SubExists be an Object and not a String?

B4X:
Dim m As SomeClassModule
' otherCodeModule is a code module in project
…
' class module
If SubExists(m,"someMethod") then
…
' code module
if SubExists(otherCodeModule,"anotherMethod") then
...

I am trying to call a sub dynamically :( .. thanks but this doesn't solve my problem
 
Upvote 0

FrostCodes

Active Member
Licensed User
Why not use the same package name in your library and app?

Actually , i wrote a library for B4J i don't know what package name someone using my library might use :(
but i would try like what you suggested if it work .. i think i can use this as a temporary solution, i can tell developers to also follow that step for now . But if any solution is available please share;)
 
Upvote 0

FrostCodes

Active Member
Licensed User
Hi, i tried using same package name. This doesn't solve my problem. I even tried putting my package name in front like this

B4X:
   CallSub3("punchline.myapi.MyModule", "MyExternalSub", "My First Paremeter", "My Second Parameter")

same failed result. I think from a server handler one cant call a sub that is external. Because i created another module in the project and tried call my sun then i used in my real app and called that sub and it worked , am i doing something wrong :( because i need to pass all parameters in the callsub3() dynamically
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
This is what I was hinting at with my previous post.
CallSub3 requires an object in the first parameter not a string
If you have a class module then you will have
B4X:
Dim x As theClass
then CallSub3 would be
B4X:
CallSub3(x,??,??,??)
If it's a code module then
B4X:
CallSub3(theCodeModuleName,??,??,??)
 
Upvote 0
Top