Android Question DDD.CollectViewsData Error?

Guenter Becker

Active Member
Licensed User
Good Day,
I am just workign with DDD.CollectViewsData.
In the project I activated the lib DesignerUtils.
I created a Layout with a single Label Named Label1.
In the Designer Script window I placed the code DDD.CollectViewsData
In the parent Class_Globals: Public dd As DDD

Code is part of a class:
sub Class_Globals
    Private xui As XUI
    Public dlgPNL As Panel
    Public dd As DDD
End Sub

Public Sub Initialize(Callback As B4XView,Eventname As String)
    mCallback = Callback
    mEventname = Eventname
    dlgPNL.initialize("")
End Sub

sub Test
   dlgPNL.RemoveAllViews
   dlgPNL.LoadLayout("Layout1")
   dlgPNL.GetView(0).As(Label).Initialize("")
   Log(dlgPNL.GetView(0).IsInitialized) ' -> [COLOR=rgb(65, 168, 95)]result is true[/COLOR]
   Log(dd.GetViewByName(dlgPNL,"TextLabelP1").IsInitialized) '->[COLOR=rgb(184, 49, 47)]error?[/COLOR]
   Log(dd.GetViewByName(dlgPNL,"TextLabelP1").Text) ' -> error?
end sub

ERROR:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Error occurred on line: 162 (DDD)
java.lang.RuntimeException: Class instance was not initialized (ddd)
at anywheresoftware.b4a.debug.Debug.shouldDelegate(Debug.java:242)
....

At present I understood that the dd was initialized by the designer if this is not correct how to initialize?.
Question: What is going wrong?
 
Solution
You are missing this step:

Q: How is the class instance created?

It depends. By default a new class instance will be created on the first time it is needed, and it will be cached. The Initialize sub of the class must not include any parameter.
The other option is to use XUI.RegisterDesignerClass to assign a specific instance that will be used.
You can get the cached class instance with XUI.GetRegisteredDesignerClass. It is probably a bit obscure for now, but these two methods are very useful.

B4X:
'before the layout is loaded
dd.Initialize
XUI.RegisterDesignerClass(dd)

Without it, there is no relation between the "dd" variable and the instance that will be created by the designer script.

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are missing this step:

Q: How is the class instance created?

It depends. By default a new class instance will be created on the first time it is needed, and it will be cached. The Initialize sub of the class must not include any parameter.
The other option is to use XUI.RegisterDesignerClass to assign a specific instance that will be used.
You can get the cached class instance with XUI.GetRegisteredDesignerClass. It is probably a bit obscure for now, but these two methods are very useful.

B4X:
'before the layout is loaded
dd.Initialize
XUI.RegisterDesignerClass(dd)

Without it, there is no relation between the "dd" variable and the instance that will be created by the designer script.
 
Upvote 0
Solution

Guenter Becker

Active Member
Licensed User
Thanky out, you did it now it works.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…