B4J Question Read Variable from inline Java code

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am trying to work out how to pass a variable from B4J to an inline Java code ?

If I have the following Class in B4J, I want to be able to run the function YourName to see the variable in B4J and then when I run RunName for it to log the name that was sent.

Is there a way in reading the variable from B4J from an inline Java code ?

B4X:
Sub Class_Globals
    Private MyName As String = "John"
End Sub

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

Public Sub YourName(Name As String)
    MyName = Name
End Sub

Public Sub RunName
    Dim jo As JavaObject = Me
    jo.RunMethod("person", Null)
End Sub

#if Java
   public static void person() {
 
      // Your name from Globals
      String JavaName = MyName;
      
      System.out.println(JavaName);

      };
#end if
 

aaronk

Well-Known Member
Licensed User
Longtime User
That worked.

The reason I am not including it in the method is is because I wanted to learn how to change it later once it has been already been set.
 
Upvote 0
Top