Android Question [SOLVED] Reflection and template argument

wonder

Expert
Licensed User
Longtime User
SOLVED: https://www.b4x.com/android/forum/threads/reflection-and-template-argument.106102/#post-664183

Hi!

This is a Reflection question, so please read-on even if you're not familiar with LibGDX.

With regards to LibGDX, I'm trying to access (with reflection) the "derivativeAt" method of the CatmullRomSpline class, but I'm unfortunately getting a NoSuchMethod exception.

upload_2019-5-24_13-38-29.png

https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/math/CatmullRomSpline.html

LibGDX CatmullRomSpline Source code:
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/math/CatmullRomSpline.java

For reference, I tried to access "valueAt", which I'm sure it works:
B4X:
Dim out As lgMathVector2

'This works!!
preview_spline.ValueAt(out, 0.5)

'This doesn't work!!
Dim r As Reflector
r.Target = preview_spline
r.RunMethod4("valueAt", Array(out, 0.5), Array As String("com.badlogic.gdx.math.Vector2", "java.lang.float"))

'java.lang.NoSuchMethodException: valueAt [interface com.badlogic.gdx.math.Vector, float]
'    at java.lang.Class.getMethod(Class.java:1981)
'    at java.lang.Class.getDeclaredMethod(Class.java:1960)
'    at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:214)
'    at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod4(Reflection.java:857)
'    at com.ninjadynamics.mangamotion.mangapage._drawpathpreview(mangapage.java:447)
'    at com.ninjadynamics.mangamotion.mangapage._drawmotionpaths(mangapage.java:360)
'    at com.ninjadynamics.mangamotion.main._lgs1_render(main.java:954)
'    at java.lang.reflect.Method.invoke(Native Method)
'    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
'    at anywheresoftware.b4a.libgdx.lgScreenManager$lgScreen.render(SourceFile:125)
'    at anywheresoftware.b4a.libgdx.lgScreenManager.Render(SourceFile:75)
'    at anywheresoftware.b4a.libgdx.LibGDX$b.render(SourceFile:156)
'    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(SourceFile:449)
'    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1553)
'    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1253)
'** Activity (main) Pause, UserClosed = true **
'waiting for pause synchronization took too long; assuming deadlock and killing

Can anyone please help or point me in the right direction? Many thanks in advance!
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
Hi!

This is a Reflection question, so please read-on even if you're not familiar with LibGDX.

With regards to LibGDX, I'm trying to access (with reflection) the "derivativeAt" method of the CatmullRomSpline class, but I'm unfortunately getting a NoSuchMethod exception.

View attachment 80669
https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/math/CatmullRomSpline.html

LibGDX CatmullRomSpline Source code:
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/math/CatmullRomSpline.java

For reference, I tried to access "valueAt", which I'm sure it works:
B4X:
Dim out As lgMathVector2

'This works!!
preview_spline.ValueAt(out, 0.5)

'This doesn't work!!
Dim r As Reflector
r.Target = preview_spline
r.RunMethod4("valueAt", Array(out, 0.5), Array As String("com.badlogic.gdx.math.Vector2", "java.lang.float"))

'java.lang.NoSuchMethodException: valueAt [interface com.badlogic.gdx.math.Vector, float]
'    at java.lang.Class.getMethod(Class.java:1981)
'    at java.lang.Class.getDeclaredMethod(Class.java:1960)
'    at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:214)
'    at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod4(Reflection.java:857)
'    at com.ninjadynamics.mangamotion.mangapage._drawpathpreview(mangapage.java:447)
'    at com.ninjadynamics.mangamotion.mangapage._drawmotionpaths(mangapage.java:360)
'    at com.ninjadynamics.mangamotion.main._lgs1_render(main.java:954)
'    at java.lang.reflect.Method.invoke(Native Method)
'    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
'    at anywheresoftware.b4a.libgdx.lgScreenManager$lgScreen.render(SourceFile:125)
'    at anywheresoftware.b4a.libgdx.lgScreenManager.Render(SourceFile:75)
'    at anywheresoftware.b4a.libgdx.LibGDX$b.render(SourceFile:156)
'    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(SourceFile:449)
'    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1553)
'    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1253)
'** Activity (main) Pause, UserClosed = true **
'waiting for pause synchronization took too long; assuming deadlock and killing

Can anyone please help or point me in the right direction? Many thanks in advance!

Try:
r.Target = preview_spline.InternalObject
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
Hi! Thanks for the quick reply!

B4X:
Dim r As Reflector
r.Target = preview_spline.InternalObject
r.RunMethod4("valueAt", Array(out, 0.5), Array As String("com.badlogic.gdx.math.Vector2", "java.lang.float"))

java.lang.NoSuchMethodException: valueAt [class com.badlogic.gdx.math.Vector2, float]

Still the same... :(
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
I found the solution! :) :D

It seems that for a template type argument, "java.lang.Object" can be used.
Also, for LibGDX the InternalObject member has to be used as well.

B4X:
Dim out as lgMathVector2
Dim r As Reflector
r.Target = preview_spline.InternalObject
Dim f = 0.5 As Float
r.RunMethod4("valueAt", Array(out, f), Array As String("java.lang.Object", "java.lang.float"))
 
Upvote 0
Top