Hi All,
I have a customlistview which has 3 files on it and a Checkbox.
The checkbox is for Default supplier. Only one of the record in the custom list view should be Ticked as there can only be one Default supplier.
So I am using the Sender function to determine which one should be Ticked and then reading the values of all of them, clearing the CLV and re-writing the values with the correct Boolean value of the Checkbox.
Code Below
This gives me an error
Which is in the createitemstock sub
if I make that line
then I get a error code on a different line
which is in the chkDefaultSupplier_checkedChange Sub
I have tried multiple ways of doing it. Seems like it needs a default value of false and not a Null
This is how the screen looks if I do not add in the Checkbox values. If i click on a Checkbox then it does read the CLV info and write it out again correctly, except all the checkboxes are always un-checked
Any Ideas, thank you
I have a customlistview which has 3 files on it and a Checkbox.
The checkbox is for Default supplier. Only one of the record in the custom list view should be Ticked as there can only be one Default supplier.
So I am using the Sender function to determine which one should be Ticked and then reading the values of all of them, clearing the CLV and re-writing the values with the correct Boolean value of the Checkbox.
Code Below
B4X:
'class globals
Type supplierproduct (supplier As String, id_product As Int,supplier_reference As String,wholesale_price As String, Currency As String, chkDfltSupplier As CheckBox)
Private Sub chkDefaultSupplier_CheckedChange(Checked As Boolean)
Log(clvSupplierItems.IsInitialized)
Dim index As Int = clvSupplierItems.GetItemFromView(Sender)
Dim stocks As List
stocks.Initialize
Log("records "&clvSupplierItems.Size)
For p = 0 To clvSupplierItems.Size-1
Dim sp As supplierproduct
Dim pnl As B4XView = clvSupplierItems.GetPanel(p)
Dim pnl2 As B4XView=pnl.GetView(0)
Log("index "&index)
If p <> index Then
sp.supplier=pnl2.GetView(0).Text
sp.supplier_reference=pnl2.GetView(2).Text
sp.wholesale_price=pnl2.GetView(1).Text
sp.Currency=pnl2.GetView(3).Text
sp.chkDfltSupplier.Checked=False
Else
sp.supplier=pnl2.GetView(0).Text
sp.supplier_reference=pnl2.GetView(2).Text
sp.wholesale_price=pnl2.GetView(1).Text
sp.Currency=pnl2.GetView(3).Text
sp.chkDfltSupplier.Checked=True
End If
stocks.Add(sp)
Next
clvSupplierItems.Clear
For t=0 To stocks.Size-1
clvSupplierItems.Add(createitemStock(stocks.Get(t)),createitemStock(stocks.Get(t)))
Next
End Sub
Sub createitemStock (supplierStock As supplierproduct ) As B4XView
Dim p As B4XView = Main.xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 35,40dip)
p.LoadLayout("SupplierItemCLVLine")
lblNameSupplier.Text=supplierStock.supplier
dtaSupplierReference.Text=supplierStock.supplier_reference
dtaSupplierPrice.Text=supplierStock.wholesale_price
dtaCurrency.Text=supplierStock.Currency
chkDefaultSupplier.Checked=supplierStock.chkDfltSupplier.Checked
p.Tag=supplierStock
Return p
End Sub
Private Sub chkSupplierItem_CheckedChange(Checked As Boolean)
Dim sp As supplierproduct
Dim index As Int = clvSuppliers.GetItemFromView(Sender)
Dim pnl As B4XView = clvSuppliers.GetPanel(index)
Dim pnl2 As B4XView = pnl.GetView(0)
Dim suppliername As String = pnl2.GetView(0).Text
Dim chksuppliers As Boolean
chksuppliers= pnl2.GetView(1).Checked
If chksuppliers = True Then
pnlSupplItems.Visible=True
sp.supplier=suppliername
Dim queryStock As String = $"
SELECT pp.wholesale_price
from pss_product as pp
where pp.id_product = ?
"$
Dim suppliersItems As dataTable
suppliersItems.Initialize(Main.sql2,queryStock,Array As String(Main.lblid.Text))
Dim queryStock As String = $"
SELECT name
from pss_currency_lang
"$
Dim currency As dataTable
currency.Initialize(Main.sql2,queryStock,Null)
sp.Currency=currency.getRowValues(0)(0)
sp.wholesale_price=suppliersItems.getRowValues(0)(0)
suppliersItem.AddAll(Array As String(suppliername))
clvSupplierItems.Add(createitemStock(sp),createitemStock(sp))
Else
Dim index As Int = suppliersItem.IndexOf(suppliername)
clvSupplierItems.RemoveAt(index)
suppliersItem.RemoveAt(index)
End If
If suppliersItem.Size= 0 Then
pnlSupplItems.Visible=False
End If
End Sub
This gives me an error
The line I get an error on isOptions
Error occurred on line: 260 (clsOptions)
java.lang.NullPointerException
at b4j.example.clsoptions._createitemstock(clsoptions.java:288)
at b4j.example.clsoptions._chksupplieritem_checkedchange(clsoptions.java:387)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA$1.run(BA.java:236)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
B4X:
chkDefaultSupplier.Checked=supplierStock.chkDfltSupplier.Checked
Which is in the createitemstock sub
if I make that line
B4X:
chkDefaultSupplier=supplierStock.chkDfltSupplier
then I get a error code on a different line
Error occurred on line: 287 (clsOptions)
java.lang.NullPointerException
at b4j.example.clsoptions._chkdefaultsupplier_checkedchange(clsoptions.java:214)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA$1.run(BA.java:236)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
which is in the chkDefaultSupplier_checkedChange Sub
B4X:
sp.chkDfltSupplier.Checked=False
I have tried multiple ways of doing it. Seems like it needs a default value of false and not a Null
This is how the screen looks if I do not add in the Checkbox values. If i click on a Checkbox then it does read the CLV info and write it out again correctly, except all the checkboxes are always un-checked
Any Ideas, thank you
Last edited: