Android Question RunMethod How to reflect objects

Wshcs

New Member
I have a class, let's say the name classa
There's a method in there, clear
I'm trying to reflect references externally,
dim a as classa
Dim r As reflect
r.Target = a
r.RunMethod("clear"), this sentence always prompts an error, what should I do, thanks
 

Wshcs

New Member
Sorry, the current input is wrong
dim a as classa
Dim r As reflector
r.Target = a
r.RunMethod("clear"), this sentence always prompts an error, what should I do, thanks
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
1. It will only work in release mode.
2. Check the generated Java code.
I had thought about Release mode, tried it but got the same error.

Now I have written a new test project, B4XPages (yesterday it was not B4XPages project, "classic" B4J and B4A). For the moment I have only tried the B4J - Release mode project and the method is not found.

EDIT: B4A - Release: same error.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
  
    Private mobjSomething As clsSomething
    Private mReflector As Reflector
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
    mobjSomething.Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
    mReflector.Target = mobjSomething
  
    mReflector.RunMethod("LogText")
  
    mReflector.RunMethod2("LogText2", "Ciao", "java.lang.String")
End Sub
clsSomething:
Sub Class_Globals
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    
End Sub

Public Sub LogText
    Log("LogText")
End Sub

Public Sub LogText2(Text As String)
    Log("LogText")
End Sub

java.lang.NoSuchMethodException: java.lang.Object.LogText()
 

Attachments

  • RunMethod_Test.zip
    9 KB · Views: 16
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
@LucaMs maybe it's like using javaobject, you have to pass the object to operate on
B4X:
mobjSomething.as(JavaObject).RunMethod("_logtext",Array(mobjSomething))
 
Upvote 1
Top