Android Question fill listview from list object

ibraheam

Member
Licensed User
Hi All

please i have the following code
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim a As MSSQL
    Dim L As List
    Dim cmdsearch As String
    Private btnsearch As Button
    Private etsearch As EditText
    Private lvresualt As ListView
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("L_Main")
    a.setDatabase("192.168.0.108","SalePointDB","sa","123")
    cmdsearch="select top 10 Item_Name from ItemSumation_VW"
    L=a.Query(cmdsearch)
    
    If L.IsInitialized=False Then
        Msgbox("Records Not Found","Warning")
        Return
    End If

    For i=0 To L.Size-1
        lvresualt.AddSingleLine(L.Get(i))
    Next
End Sub

the problem is the application stopped as soon as it start
please can i fine help
 

ibraheam

Member
Licensed User
Logs, please!
thank you kmatle for reply , below logs


Logger connected to: samsung SM-G610F
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
main_btnsearch_click (java line: 391)
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.collections.List.Clear(List.java:69)
at b4a.example.main._btnsearch_click(main.java:391)
at java.lang.reflect.Method.invoke(Native Method)
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:78)
at android.view.View.performClick(View.java:6261)
at android.widget.TextView.performClick(TextView.java:11185)
at android.view.View$PerformClick.run(View.java:23752)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
Logger connected to: samsung SM-G610F
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
main_btnsearch_click (java line: 391)
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.collections.List.Clear(List.java:69)
at b4a.example.main._btnsearch_click(main.java:391)
at java.lang.reflect.Method.invoke(Native Method)
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:78)
at android.view.View.performClick(View.java:6261)
at android.widget.TextView.performClick(TextView.java:11185)
at android.view.View$PerformClick.run(View.java:23752)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (List).
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
 
Upvote 0

ibraheam

Member
Licensed User
thank you BeneBarros and Erel for reply about listview initializing, it is add with designer so it do not need initializing

about btnsearch_click below the script

B4X:
Sub btnsearch_Click
   Try
       If etsearch.Text<>"" Then
       lvresualt.Clear
       L.Clear
       cmdsearch="select top 100 Item_Name,TotalBoxQty,TotalPieceQty from ItemSumation_VW where ID=" & etsearch.Text
       L=a.Query(cmdsearch)
       Dim i As Int=0
       For i=0 To L.Size-1
           lvresualt.AddSingleLine(L.Get(i))
       Next
   End If
   Catch
       Log(LastException)
   End Try
End Sub

and please can you guid me to the JdbcSQL library ,it will be best if there is an example about it

best regards
 
Upvote 0
Top