Java Question [SOLVED] Problem with JavaObecjt RunMethod

Star-Dust

Expert
Licensed User
Longtime User
I'm creating a library that contains some riche in Java and I have a problem, running I can not find the method.

Here is the code:
B4X:
Sub Class_Globals
   
End Sub

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

public Sub MyMethod(Param1 As String, Param2 As String)
    Dim J As JavaObject = GetBA
    'J.InitializeContext
    J.RunMethod("NewMethod", Array(Param1,Param2))
End Sub

Private Sub GetBA As Object
    Dim jo As JavaObject = Me
    Return jo.RunMethod("getBA", Null)
End Sub

#if java
import java.io.*;
//import java.util.*;

   public void NewMethod(String p1, String p2) throws IOException {

    }
#End if

I have already understood that initialize context does not work in this case but only on activity and service ... I tried GetBA as suggested by @Erel for other circumstances, but still nothing ...

While I put the code in the activity and initialize it with InitializeContext, it works correctly, but this was obvious.
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
The solution is very simple, silly that I had not thought about it:
B4X:
public Sub MyMethod(Param1 As String, Param2 As String)
    Dim J As JavaObject = Me
    'J.InitializeContext
    J.RunMethod("NewMethod", Array(Param1,Param2))
End Sub
 
Top