How do you generate a GUID??

alvinmb

Member
Licensed User
Longtime User
I have a requirement to generate a GUID for each request that I send to a server. Android has a UUID class. How would you do this in B4A?
 

emockler

Member
Licensed User
Longtime User
I would normally not necropost, but my question is highly relevant.
I am using the above verbatim, a button click should make a new uuid
however, I am getting java lang NoSuchMethodException:tostring

as I test, I would add msgbox("my new uuid","") and see my correctly generated uuid, but I am unsure what to put in place of "my new uuid"

I'm using reflection 2.40
 
Upvote 0

emockler

Member
Licensed User
Longtime User
Hi Erel,
I have this in globals:

Dim r As Reflector

and do this with a button click:

Sub nuuid_click As String
r.Target = r.RunStaticMethod("java.util.UUID", "randomUUID", Null, Null)
Return r.RunMethod("ToString")

End Sub


I get this when I click the button:

Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:anywheresoftware.b4a.samples.xmlsax
** Activity (main) Create, isFirst = true **
>>> [SSH]: Connection was successfully established.
>>> [SSH]: Starting download of file 'Win10.xml' with TaskId 12...
>>> [SSH]: Command was successfully executed.
>>> [SSH]: Connection was successfully established.
>>> [SSH]: Task with ID 25 is already running...
** Activity (main) Resume **
>>> [SSH]: Connection was successfully established.
>>> [SSH]: Command was successfully executed.
>>> [SSH]: Command was successfully executed.
main_nuuid_click (java line: 669)
java.lang.NoSuchMethodException: ToString() []
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getDeclaredMethod(Class.java:685)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:214)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod(Reflection.java:802)
at anywheresoftware.b4a.samples.xmlsax.main._nuuid_click(main.java:669)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14105)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NoSuchMethodException: ToString() []

Thanks!
 
Upvote 0

emockler

Member
Licensed User
Longtime User
Thanks Erel,
I changed ToString to toString and it no longer throws the error.
Is that what you identified as incorrect?
However, I still don't know how to get the generated UUID.
How would I display the new UUID, say in a msgbox("????","") ?

Thanks!
 
Upvote 0
Top