Android Question Why Type in code module not recognized by B4XMainPage?

RB Smissaert

Well-Known Member
Licensed User
Longtime User
In B4XMainPage I have this code:

B4X:
Sub Class_Globals
    Private ser As B4XSerializator
End Sub

Sub GetSQL_ExtraFromTable(strNameOfSQL As String, _
                          iFolderID As Int, _
                          strRunSQL As String) As tSQL_Extra
    
    Dim strSQL As String
    Dim RS1 As ResultSet
    Dim arrBytes() As Byte
    Dim tSE As tSQL_Extra 'this type is in the code module Enums
    
    If strRunSQL.Length > 0 Then
        strSQL = "select sql_extra from run_sql where sql = ? and length(sql_extra) > 0"
        RS1 = cConn.SQLNon_Clinical.ExecQuery2(strSQL, Array As String(strRunSQL))
    Else
        strSQL = "select sql_extra from saved_sql where name = ? and folder_id = ? and length(sql_extra) > 0"
        RS1 = cConn.SQLNon_Clinical.ExecQuery2(strSQL, Array As String(strNameOfSQL, iFolderID))
    End If
    
    'Log("GetSQL_ExtraFromTable, RS1.RowCount: " & RS1.RowCount)
    
    If RS1.RowCount = 0 Then
        Return tSE 'return un-initialized type
    End If
    
    RS1.Position = 0
    arrBytes = RS1.GetBlob2(0)
    
    'Log("GetSQL_ExtraFromTable, arrBytes.Length: " & arrBytes.Length)
    
    tSE.Initialize
    tSE = ser.ConvertBytesToObject(arrBytes) '<<<<< java.lang.RuntimeException: java.lang.ClassNotFoundException: b4a.exampleljjll.b4xmainpage$_tsql_extra
    
    RS1.Close

    Return tSE

End Sub

In a code module called Enums I have the this type:

B4X:
    Type tSQL_Extra(strData_Types As String, _
                    bChartDataTypes As Boolean, _
                    strChart_Title As String, _
                    strChartLine_Names As String, _
                    strSQLForDate_Line1 As String, _
                    strSQLForDate_Line2 As String, _
                    strColumnWidths As String, _
                    bRun_Chart As Boolean, _
                    bGraphXProportional As Boolean, _
                    bChartTitleInPatLabel As Boolean, _
                    bActive As Boolean, _
                    strSQL As String, _
                    strSQLName As String)

If I run GetSQL_ExtraFromTable from B4XMainPage then I get this error:

java.lang.RuntimeException: java.lang.ClassNotFoundException: b4a.exampleljjll.b4xmainpage$_tsql_extra
at the line marked above.

If I declare the type in B4XMainPage, Sub Class_Globals then GetSQL_ExtraFromTable runs fine.
Other types declared in the code module Enums are recognized fine by Subs in B4XMainPage and I thought that Types declared in code modules should
be recognized by all the modules in a project, so why is this particular case different?

RBS
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

teddybear

Well-Known Member
Licensed User
OK, thanks, will move them all over then.
I have many types declared though in that code module and they all are recognized perfectly fine by Subs in B4XMainPage.
Why this one behaves different?

RBS
You don't have to remove them all. as you said they all are recognized perfectly fine by Subs in B4XMainPage.
Why this one behaves different?
That is just because The Custom types should be defined in the Main or B4XMainPage module when using B4XSerializator to serialize them.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
You don't have to remove them all. as you said they all are recognized perfectly fine by Subs in B4XMainPage.
Why this one behaves different?
That is just because The Custom types should be defined in the Main or B4XMainPage module when using B4XSerializator to serialize them.
> The Custom types should be defined in the Main or B4XMainPage module when using B4XSerializator to serialize them

OK, thanks, so this only applies to Types to be serialized by B4XSerializator?
That will save me quite a bit of work then!

RBS
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
OK, thanks, so this only applies to Types to be serialized by B4XSerializator?
More accurately:
If you want to serialize a custom type in one B4X app and deserialize it in another B4X app then the type must be defined in Main or B4XMainPage modules. In other cases you can define the type in other modules.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
More accurately:
If you want to serialize a custom type in one B4X app and deserialize it in another B4X app then the type must be defined in Main or B4XMainPage modules. In other cases you can define the type in other modules.
Well, in my case there is only one app. The type is serialized and either saved to KVS or saved as a blob to a local SQLite database (using SQLCipher) and then deserialized and used in the same app. So, to me it seems there can be a problem even if only one app is involved.

RBS
 
Upvote 0
Top