Use case:
The attached B4J-test project is an extract from a larger B4A project. The layout was transferred via copypaste in the designer.
Problems:
I'd appreciate it if someone here could help me back on the saddle.
(Small B4J Testproject attached)
A clv contains several entries whose content depends on the date in the adp.
If the date is changed via adp, the contents on the affected clvitem will be recalculated. The new date and the new contents will be saved and the affected clvitem will be updated.
If the date is changed via adp, the contents on the affected clvitem will be recalculated. The new date and the new contents will be saved and the affected clvitem will be updated.
The attached B4J-test project is an extract from a larger B4A project. The layout was transferred via copypaste in the designer.
Problems:
1. An error occurs which cannot be traced due to a lack of B4J experience.
B4X:
private Sub CreateItem_c4list(NameVal As String, DatVal As String, Index As Int, PanelHeight As Int) As B4XView
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, c0tabCLV_c4list.AsView.Width, 200dip)
p.LoadLayout("clvitemdat") ' <---
datPanelLabelName.Text = NameVal
AnotherDatePicker1.Date = DateTime.DateParse(DatVal)
Return p
End Sub
main._createitem_c4list (java line: 113)
java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
at anywheresoftware.b4j.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:68)
at anywheresoftware.b4j.objects.LayoutBuilder.loadLayout(LayoutBuilder.java:93)
at anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(PaneWrapper.java:84)
at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:486)
at b4j.example.main._createitem_c4list(main.java:113)
at b4j.example.main._appstart(main.java:94)
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.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.start(main.java:37)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
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)
Caused by: java.lang.NullPointerException
at b4j.example.anotherdatepicker$ResumableSub_DesignerCreateView.resume(anotherdatepicker.java:327)
at b4j.example.anotherdatepicker._designercreateview(anotherdatepicker.java:281)
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.BA.raiseEvent2(BA.java:91)
... 22 more
2. If the date of the adp was changed, the index of the affected clv item should be determined in order to persistently change the affected data record.
3. After the contents of the affected clv item have been recalculated, the display of the clv item should be updated.
4. Own experiments in the B4A project led to endless updates, which could not be avoided even with a global "skipevent variable".
3. After the contents of the affected clv item have been recalculated, the display of the clv item should be updated.
4. Own experiments in the B4A project led to endless updates, which could not be avoided even with a global "skipevent variable".
B4X:
Sub AnotherDatePicker1_DateChanged (NewDate As Long) As ResumableSub
Log("#-Sub AnotherDatePicker1_DateChanged, SkipEvents=" & SkipEvents & ", NewDate = " & NewDate & $" --> $Date{NewDate}"$)
If SkipEvents Then Return
SkipEvents = True
Dim x As AnotherDatePicker = Sender
Dim xMap As Map = x.mBase.Tag
Dim ClvIndex As Int = xMap.get("ClvIndex")
Dim p As B4XView = CreateItem_c4list(xMap, ClvIndex) ' --> In AnotherDatePicker1_DateChanged
c0tabCLV_c4list.ReplaceAt(ClvIndex, p, p.Height, "" )
c0tabCLV_c4list.ScrollToItem(ClvIndex)
SkipEvents = False
Sleep(0)
End Sub
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 400
#End Region
' --> file:///.\Objects\src\b4j\example
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim xui As XUI
Private AnotherDatePicker1 As AnotherDatePicker
Private c0tabCLV_c4list As CustomListView
Private datPanelLabelName As B4XView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("clvpanel") 'Load the layout file.
MainForm.Show
Dim DatMap As Map
DatMap.Initialize
DatMap.Put("Miller", "11.03.2005")
DatMap.Put("Smith", "11.03.2005")
Dim i As Int = 0
For Each k As String In DatMap.Keys
Dim p As B4XView = CreateItem_c4list(k, DatMap.Get(k), i, 300dip ) ' --> In C0FillContentPage_c4list
c0tabCLV_c4list.Add(p, i)
i = i +1
Next
End Sub
private Sub CreateItem_c4list(NameVal As String, DatVal As String, Index As Int, PanelHeight As Int) As B4XView
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, c0tabCLV_c4list.AsView.Width, 200dip)
p.LoadLayout("clvitemdat")
datPanelLabelName.Text = NameVal
AnotherDatePicker1.Date = DateTime.DateParse(DatVal)
Return p
End Sub
Sub AnotherDatePicker1_DateChanged (NewDate As Long)
Log($"New date $Date{NewDate}"$)
Dim adpX As AnotherDatePicker = Sender
' ... get index of clvitem
' ... change underlaying data
' ... modify visible content on edited clvitem panel
End Sub
I'd appreciate it if someone here could help me back on the saddle.
(Small B4J Testproject attached)