Android Question JDBC MySQL problem in Release version

Juanll2003uy

Member
Licensed User
Longtime User
Hi, i have an app example with mysql connection which in debug mode it works fiine, but in the release version the app crash and dont run.

Can someone help me? Thanks

The code is this:

Main code:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region
'#AdditionalJar: mysql-connector-java-5.1.34-bin
#AdditionalJar: mysql-connector-java-5.1.40-bin
#BridgeLogger: true
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private ProgressBar1 As ProgressBar
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")

End Sub

Sub Activity_Click
    ProgressBar1.Visible = True
    Wait For (CallSub(Starter, "ListAnimals")) Complete (Result As Boolean)
    Log("Completed. Success: " & Result)
    ProgressBar1.Visible = False
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Starter code:
#Region  Service Attributes


    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    Public mysql As JdbcSQL
    Private driver As String = "com.mysql.jdbc.Driver"
    Private jdbcUrl As String = "jdbc:mysql://192.168.0.2/SQLTutorial"
    Private Username As String = "pippo"
    Private Password As String = "xxxxx"
End Sub
Sub Service_Create
    DisableStrictMode
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub DisableStrictMode
    Dim jo As JavaObject
    jo.InitializeStatic("android.os.Build.VERSION")
    If jo.GetField("SDK_INT") > 9 Then
        Dim policy As JavaObject
        policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
        policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
        Dim sm As JavaObject
        sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
    End If
End Sub

Sub Connect As ResumableSub
    mysql.InitializeAsync("mysql", driver, jdbcUrl, Username, Password)
    Wait For MySQL_Ready (Success As Boolean)
    If Success = False Then
        Log("Check unfiltered logs for JDBC errors.")
    End If
    Return Success
End Sub

Sub CloseConnection
     mysql.Close
End Sub

Sub ListAnimals As ResumableSub
    Wait For (Connect) Complete (Success As Boolean)
    If Success Then
        Try
            Dim sf As Object = mysql.ExecQueryAsync("mysql", "SELECT ID, PartNo FROM Products WHERE ID > ?", Array(300))
            Wait For (sf) mysql_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
            If Success Then
                Do While Crsr.NextRow
                    Log($"ID: ${Crsr.GetInt("ID")}, PartNo: ${Crsr.GetString("PartNo")}"$)
                Loop
                Crsr.Close
            End If
        Catch
            Success = False
            Log(LastException)
        End Try
        CloseConnection
    End If
    Return Success
End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub
 

Juanll2003uy

Member
Licensed User
Longtime User
Hi, the error message is this:


The code there is this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    First_Time=True
    Activity.LoadLayout("Main")
    'Activity.SetBackgroundImage(LoadBitmapSample(File.DirDefaultExternal, "back.jpg", 592, 585))
    OK=False
    DateTime.DateFormat="yyyy-MM-dd"
    
    cdb.Initialize(Colors.RGB(255,255,255), 42)
    cdb2.Initialize(Colors.RGB(0,131,170), 1)
    
    Dim rp As RuntimePermissions
    If File.Exists(rp.GetSafeDirDefaultExternal(""), "BaseDatos.db")=False Then
        File.Copy(File.DirAssets,"BaseDatos.db",rp.GetSafeDirDefaultExternal(""),"BaseDatos.db")
    End If
    If Conn.IsInitialized = False Then
        Conn.Initialize(rp.GetSafeDirDefaultExternal(""), "BaseDatos.db", True)
    End If
    
    mCPPar.Initialize(Conn)
    
    btnClientes.Background=cdb
    btnRemitos.Background=cdb
    btnProductos.Background=cdb
    btnVentas.Background=cdb
    btnSalir.Background=cdb
    btnDevoluciones.Background=cdb
    btnGastos.Background=cdb
    btnCobranza.Background=cdb
    btnEstCta.Background=cdb
    btnListados.Background=cdb
    
    txtUsu1.Background = cdb2
    txtPass.Background = cdb2
    
    txtUsu1.Text=mCPPar.Buscar_Mail1
    txtPass.Text=mCPPar.Buscar_Contrasena
    
End Sub
 
Upvote 0

Juanll2003uy

Member
Licensed User
Longtime User
In debug mode show the error but it works. In release it crash.
The main.bal exists i dont understand what happens
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Try searching, there are several threads about that, that's why is so important to know the error you get


 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…