"An Activity context is required" error occurs when no activity context is required

corwin42

Expert
Licensed User
Longtime User
I get the following error in a class module:

B4X:
Compiling code.                         Error
Error compiling program.
Error description: An Activity context is required.
This class has a process context.
Adding a global "Activity object" variable will fix this issue.
Occurred on line: 51
UpdateInterval.Put(C.PREFS_UPDINTERVAL_30M, Util.GetText("30 minutes"))
Word: gettext

It seems that this error occurs if I just call a sub in a code module (here Util.GetText). Util.GetText uses only AHTranslator object which is declared as process global variable. So I don't think that an activity context is needed here.

I can fix this with adding a dummy panel to the class which is never used. But I don't know why the compiler needs activity context.

Sorry, I currently don't have a small example project for the issue.

Edit: Hmm, in this context I can't add a dummy panel because I need an instance of this class as process globals variable.
 
Last edited:

RobertJurado

Member
Licensed User
Longtime User
I am having the same issue!

I upgraded to Ver 2.02. Now I am trying to use the Class Modules, but it seems that I cannot call a function in a code module from the new Class Module.

Here is Sample....


'Class module
Sub Class_Globals
Private nBalance As Double ' I played with Private and/or Public

End Sub


Public Sub Initialize(data As Map)

nBalance = data.GetDefault("BalanceDue","0")

End Sub



Public Sub GetBalance As String
Dim sResult As String
sResult = Common.ExtractMoney(nBalance)
Return sResult
End Sub

... Where Extract Money is a Code Module (named Common) ...

Sub ExtractMoney(RowCol As Double) As String
Dim sResult As String

sResult = "$ " & NumberFormat2(RowCol,1,2,2,False)

Return sResult
End Sub

.... Thanks in advance for any information


Robert
 
Top