B4J Question How can i display MsgBox in a loop with Wait For

Brian Michael

Active Member
Licensed User
Hi, im trying to show a Messagebox if an item of a list exist, if the item exist i want to ask if you want Replace the data or just Decline.

I use this code:

B4X:
Public Sub importData(Database As List, newItems As List, option As Int) As ResumableSub
    Log("Importando datos... Productos a importar: " & newItems.Size)
    Dim DB As List = Database
    Dim a As Int = 0
    For Each item As Map In newItems
            a=a+1
            Log("Verificando dato: " & a)
        If option = 0 Then   
            If DB.IndexOf(item.Get("CODIGO")) = -1 Then
                For i = 0 To DB.Size - 1
                    'Log("Verificando ML " & (i+1) & " de " & MasterList.Size)
                    Dim tempRecord As Map = DB.Get(i)
                    If item.Get("CODIGO") == tempRecord.Get("CODIGO") Then
                        Wait For (ShowDialog(item)) Complete (Result As Int)
                        If Result = -1 Then
                            'MasterList.Set(i, record)
                            Log("Producto : " & item.Get("CODIGO") & " fue reemplazado correctamente")
                        End If
                    End If
                Next
            Else
                Log("Nuevo Producto : " & item.Get("CODIGO") & " fue agregado correctamente")
            End If
        End If
        
    Next
    Return DB
End Sub

Private Sub ShowDialog(old As Map) As ResumableSub
    Return Msg.show2("¿El producto " & old.Get("CODIGO") & " - " & old.Get("PRODUCTO") & " ya existe desea reemplazar sus datos?,","Aviso","Si","No","")
End Sub


And i get this error:

java.lang.NullPointerException
at b4j.example.masivedata$ResumableSub_importData.resume(masivedata.java:370)
at b4j.example.masivedata._importdata(masivedata.java:213)
at b4j.example.main$ResumableSub_btnConvert_Click.resume(main.java:1100)
at b4j.example.main._btnconvert_click(main.java:1074)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:216)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)

I just want to show a msgbox asking if you want to replace the existing item or not
 

Brian Michael

Active Member
Licensed User
I'm so sorry, the error I was receiving was different from the post, I managed to see the error after publishing this post, any member of staff please delete this post.
Thanks and apologies for the inconvenience.
 
Upvote 0
Top