B4J Question problemas cuando guardo

jjmairena

Member
Licensed User
Longtime User
hi there... friends will anyone could help me with this error ??

Program started.
Error occurred on line: 51 (codproveedores).
java.lang.NullPointerException
at b4j.example.codproveedores._gridproveedor_selectedrowchanged(codproveedores.java:395)
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:497)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:563)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:221)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
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:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA$2.run(BA.java:165)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(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$149(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

this is my code:

MySQL.SQLCon.ExecNonQuery ("UPDATE `proveedor` SET `Proveedor`='" & TextField1.Text & "',`CedJuridica`='" & TextField2.Text & "',`CuentaB`='" & TextField3.Text & "',`tel1`='" & TextField4.Text & "',`tel2`='" & TextField5.Text & "',`Mail`='" & TextField6.Text & "',`Web`='" & TextField7.Text & "',`Plazo`='" & TextField8.Text & "' WHERE id='" & IdProveedor & "'")
rsProveedor=MySQL.SQLCon.ExecQuery("SELECT * from proveedor where Empresa= '" & Main.Empresa & "'")
GridProveedor.SetColumns(Array As String("Proveedor","Ced Juridica","Cta bancaria", "Telefono","Telefono2","Mail","Web","Plazo","Id"))
Do While rsProveedor.NextRow
Dim row(9) As Object
row(0) = rsProveedor.GetString("Proveedor")
row(1) = rsProveedor.GetString("CedJuridica")
row(2) = rsProveedor.GetString("CuentaB")
row(3) = rsProveedor.GetString("tel1")
row(4) = rsProveedor.GetString("tel2")
row(5) = rsProveedor.GetString("Mail")
row(6) = rsProveedor.GetString("Web")
row(7) = rsProveedor.GetString("Plazo")
row(8) = rsProveedor.GetString("Id")
GridProveedor.Items.Add(row)
Loop
rsProveedor.Close
GridProveedor.SetColumnWidth(0,500)
Toast.ToastShow("El registro fue editado satisfactoriamente")
 

jjmairena

Member
Licensed User
Longtime User
B4X:
'Static code module
Sub Process_Globals
    Private fx As JFX
    Private Proveedores As Form
    Dim TextField1 As TextField
    Dim TextField2 As TextField
    Dim TextField3 As TextField
    Dim TextField4 As TextField
    Dim TextField5 As TextField
    Dim TextField6 As TextField
    Dim TextField7 As TextField
    Dim TextField8 As TextField
    Dim rsProveedor As ResultSet
    Dim MsgBox As Msgboxes
    Private Toast As ToastMessageShow
    Private GridProveedor As TableView
    Public IdProveedor As Int
    Private count As Int
    Dim av As Int
End Sub
Sub Show 
    Proveedores.Initialize("frm", 490, 600)
    Proveedores.RootPane.LoadLayout("Proveedores")
    Proveedores.Show
    rsProveedor=MySQL.SQLCon.ExecQuery("SELECT * from proveedor where Empresa= '" & Main.Empresa & "'")
    GridProveedor.SetColumns(Array As String("Proveedor","Ced Juridica","Cta bancaria", "Telefono","Telefono2","Mail","Web","Plazo","Id"))
    Do While rsProveedor.NextRow
        Dim row(9) As Object
        row(0) = rsProveedor.GetString("Proveedor")
        row(1) = rsProveedor.GetString("CedJuridica")
        row(2) = rsProveedor.GetString("CuentaB")
        row(3) = rsProveedor.GetString("tel1")
        row(4) = rsProveedor.GetString("tel2")
        row(5) = rsProveedor.GetString("Mail")
        row(6) = rsProveedor.GetString("Web")
        row(7) = rsProveedor.GetString("Plazo")
        row(8) = rsProveedor.GetString("Id")
        IdProveedor = rsProveedor.GetString("Id")
        GridProveedor.Items.Add(row)
    Loop
    rsProveedor.Close   
    GridProveedor.SetColumnWidth(0,500)
    Toast.Initialize("Toast")
    Toast.ToastIconSize32x32
    Toast.ToastDuration = 2 'Toast.TOAST_LONG_DELAY
    Toast.ToastTextLocation = Toast.TEXT_CENTER
    Toast.ToastLocation= Toast.TOAST_CENTER_RIGHT
    Toast.ToastNotificationOwner = Proveedores
End Sub
Sub GridProveedor_SelectedRowChanged(Index As Int, Row() As Object)
    TextField1.Text= Row(0)
    TextField2.Text= Row(1)
    TextField3.Text= Row(2)
    TextField4.Text= Row(3)
    TextField5.Text= Row(4)
    TextField6.Text= Row(5)
    TextField7.Text= Row(6)
    TextField8.Text= Row(7)
    IdProveedor= Row(8)
End Sub
Sub BSalir_Action
    Proveedores.Close  
End Sub
Sub BNuevo_Action
    TextField1.Text= ""
    TextField2.Text= ""
    TextField3.Text= ""
    TextField4.Text= ""
    TextField5.Text= ""
    TextField6.Text= ""
    TextField7.Text= ""
    TextField8.Text= ""
    av=1
End Sub
Sub Ingresa
    rsProveedor=    MySQL.SQLCon.ExecQuery("SELECT * from proveedor where Proveedor='" & TextField1.Text & "' and CedJuridica='" & TextField2.Text & "' and Empresa= '" & Main.Empresa & "'")
    Do While  rsProveedor.NextRow 
        count=count +1
    Loop
    If count >0 Then   
        Toast.ToastMessageColor = fx.Colors.White
          Toast.ToastShow("El proveedor que usted digitó ya se encuentra en la base de datos")
    Else   
        MsgBox.Show(Main.Empresa,"j")
        MySQL.SQLCon.ExecNonQuery2("INSERT INTO proveedor VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object ("0",TextField1.Text,TextField2.Text,TextField3.Text,TextField4.Text,TextField5.Text,"0",TextField6.Text,TextField7.Text ,"0","0","0","0",TextField8.Text,"0",Main.Empresa))
        rsProveedor=MySQL.SQLCon.ExecQuery("SELECT * from proveedor where Empresa= '" & Main.Empresa & "'")
        GridProveedor.SetColumns(Array As String("Proveedor","Ced Juridica","Cta bancaria", "Telefono","Telefono2","Mail","Web","Plazo","Id"))
        Do While rsProveedor.NextRow
            Dim row(9) As Object
            row(0) = rsProveedor.GetString("Proveedor")
            row(1) = rsProveedor.GetString("CedJuridica")
            row(2) = rsProveedor.GetString("CuentaB")
            row(3) = rsProveedor.GetString("tel1")
            row(4) = rsProveedor.GetString("tel2")
            row(5) = rsProveedor.GetString("Mail")
            row(6) = rsProveedor.GetString("Web")
            row(7) = rsProveedor.GetString("Plazo")
            row(8) = rsProveedor.GetString("Id")
            GridProveedor.Items.Add(row)
        Loop
        rsProveedor.Close   
        GridProveedor.SetColumnWidth(0,500)
        Toast.ToastShow("El registro fue creado satisfactoriamente")
    End If
End Sub
Sub Modifica
    MySQL.SQLCon.ExecNonQuery ("UPDATE `proveedor` SET `Proveedor`='" & TextField1.Text & "',`CedJuridica`='" & TextField2.Text & "',`CuentaB`='" & TextField3.Text & "',`tel1`='" & TextField4.Text & "',`tel2`='" & TextField5.Text & "',`Mail`='" & TextField6.Text & "',`Web`='" & TextField7.Text & "',`Plazo`='" & TextField8.Text & "' WHERE id='" & IdProveedor & "'")
    rsProveedor=MySQL.SQLCon.ExecQuery("SELECT * from proveedor where Empresa= '" & Main.Empresa & "'")
    GridProveedor.SetColumns(Array As String("Proveedor","Ced Juridica","Cta bancaria", "Telefono","Telefono2","Mail","Web","Plazo","Id"))
    Do While rsProveedor.NextRow
        Dim row(9) As Object
        row(0) = rsProveedor.GetString("Proveedor")
        row(1) = rsProveedor.GetString("CedJuridica")
        row(2) = rsProveedor.GetString("CuentaB")
        row(3) = rsProveedor.GetString("tel1")
        row(4) = rsProveedor.GetString("tel2")
        row(5) = rsProveedor.GetString("Mail")
        row(6) = rsProveedor.GetString("Web")
        row(7) = rsProveedor.GetString("Plazo")
        row(8) = rsProveedor.GetString("Id")
        GridProveedor.Items.Add(row)
    Loop
    rsProveedor.Close   
    GridProveedor.SetColumnWidth(0,500)
    Toast.ToastShow("El registro fue editado satisfactoriamente")
End Sub
Sub BGuardar_Action
    If av=1 Then
        Ingresa
    Else   
        Modifica
    End If
    av=0
End Sub
Sub BCancelar_Action
    av=0
End Sub

Sub TextField8_TextChanged (Old As String, New As String)
    Dim len As Int
    Dim chr1 As Char

    If Old.ToUpperCase = New Then Return    ' exits upper case change

    len = New.Length
    If len > 0 Then
    New = New.ToUpperCase
    For i = 0 To len-1
    chr1 = New.CharAt(i)
    If "1234567890.".Contains(chr1) = False Then
    len = Old.Length
    TextField8.Text = Old
    TextField8.SetSelection(len, len)
    Return
    End If
    Next
    Else
    TextField8.Text = ""
    Return
    End If

    TextField8.Text = New    ' text changed to upper case
    TextField8.SetSelection(len, len)   
End Sub
 
Upvote 0

jjmairena

Member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Where is line number 51?

Where is the SelectedRowChanged sub?

hola pude resolver el problema anterior pero encontre otro en este mismo módulo, esto sucede cuando actualizo cualquier registro si salgo del layouts y vuelvo entrar me da este error
B4X:
Program started.
codproveedores._show (java line: 356)
java.lang.IllegalStateException: Cannot set owner once stage has been set visible
    at javafx.stage.Stage.initOwner(Stage.java:561)
    at anywheresoftware.giuseppe.salvi.toast.notification.ToastNotification$ToastNotifier.setPopupLocation(ToastNotification.java:145)
    at anywheresoftware.giuseppe.salvi.toast.ToastMessageShowWrapper.setToastNotificationOwner(ToastMessageShowWrapper.java:171)
    at b4j.example.codproveedores._show(codproveedores.java:356)
    at b4j.example.main._menubar1_action(main.java:217)
    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:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.BA$2.run(BA.java:165)
    at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(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$149(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Toast.ToastNotificationOwner = Proveedores

esta es la linea que te esta dando el problema quitala y ponla donde se corra una sola vez, el problema es que si ya pusiste un "Owner" no lo puedes volver a poner.
 
Upvote 0
Top