Android Question Run OK in debug but in Release it stops

drnet

New Member
Licensed User
Hi everyone, that's my first post, I've started to program in B4A yesterday and I downloaded the MSSQL library.

I created a small program that calls to my MSSQL database without any trouble, I get the data, make the phone call, etc, etc, etc... but it's only working in Debug mode, if I create the release, the app crash when I select request the select to MSSQL.

When I press the "buttonactualizar" crash and the log says:

main_buttonactualizar_click (java line: 404)
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.collections.List.getSize(List.java:129)
at b4a.example.main._buttonactualizar_click(main.java:404)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

I need to make some special for add external libraries to the android devices?

thanks
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
You have posted your question in the wrong place. Here is for Tutorials and Example.
Next time post your questions in B4A Questions page.

To answer your question, it seems there is a list you didn't initialize in the buttonactualizar_click event. Here is an example how to initialize the list

B4X:
Dim MyList as List
List.Initialize
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
Dim MyList as List
List.Initialize
B4X:
Dim MyList as List
MyList.Initialize
 
Upvote 0

drnet

New Member
Licensed User
In sub globals I've 2 lists:

Dim resSQL1 As List
Dim resSQL2 As List

I put

resSQL1.Initialize
resSQL2.Initialize

In globals and I tried in Sub ButtonActualizar_Click, the error is the same

The code is not big, I attach here (Covered the SQL database options obviously):

#Region Project Attributes
#ApplicationLabel: ASI
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#BridgeLogger: True

#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

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.


Dim sf As StringFunctions
sf.Initialize

Dim varSQL1 As MSSQL
Dim varSQL2 As MSSQL
Dim varSQL3 As MSSQL
Dim resSQL1 As List
Dim resSQL2 As List
'Dim resSQL3 As List
resSQL1.Initialize
resSQL2.Initialize

'Dim i As Int
Dim varMovil As Int
Dim varNumero As String

' Private Button1 As Button
Private ButtonActualizar As Button
Private RadioButton2 As RadioButton
Private RadioButton1 As RadioButton
Private Label1 As Label
Private ListView1 As ListView
Private ButtonLlamar As Button
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("main")
RadioButton1.Checked = True


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click

End Sub

Sub ButtonActualizar_Click
resSQL1.Initialize
resSQL2.Initialize
If RadioButton1.Checked = True Then
varMovil = 1
End If
If RadioButton2.Checked = True Then
varMovil = 2
End If

varSQL1.setdatabase("DATABASE INFO HERE")
varSQL2.setdatabase("DATABASE INFO HERE")
varSQL3.setdatabase("DATABASE INFO HERE")
'L = a.TableList
resSQL1=varSQL1.Query("select id_cliente from agua.pedidos where movil_pedido = " & varMovil & " and estado_pedido = 2")

Dim varNombre As String
Dim varTelefono As String
Dim varLimite As Int
varLimite = resSQL1.Size -1
ListView1.Clear
For i = 1 To varLimite
varTelefono = resSQL1.Get(i)
varTelefono = varTelefono.Replace("[","")
varTelefono = varTelefono.Replace("]","")
resSQL2=varSQL2.Query("select nombre_cliente from agua.clientes where fono_cliente = '" & varTelefono & "'")
varNombre = resSQL2.Get(1)
varNombre = varNombre.Replace("[","")
varNombre = varNombre.Replace("]","")
ListView1.AddSingleLine(varTelefono & " " & varNombre)
Next

End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
ButtonLlamar.Enabled=True
varNumero = sf.Left(Value,9)

'Msgbox (varNumero,"a")
ButtonLlamar.Text = "Llamar a " & varNumero
End Sub

Sub ButtonLlamar_Click
Dim call As Intent
call.Initialize(call.ACTION_VIEW, "tel:" & varNumero)
StartActivity(call)

End Sub
 
Upvote 0

drnet

New Member
Licensed User
I addded:

If resSQL1.IsInitialized=False Then
Msgbox("Error","Error")
End If

I get the msgbox... I guess that the problem is that is not calling to the MSSQL database or loading the MSSQL Library, the question is why in debug mode works but in release don't
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
found something in Erels Debugging tutorial video today.
you can enable log in release mode with
#BridgeLogger: True
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I found the problem, I removed in the manifest "android:targetSdkVersion:##"
This is of course not the real problem and not the correct solution (and Google will soon not allow it anyway).

There are two "problems":
1. You must be able to read logs in order to understand the error.
2. The library sends the requests on the main thread. Don't use such libraries.
You can disable the network on main thread check, however your app will still freeze and eventually be killed by the OS.

Switch to JdbcSQL and use the async methods.
 
Upvote 0
Top