Android Question Is this a bug or I forgot the most basic command ?

rdkartono

Member
Licensed User
Long time not touching B4A.

I just want to create a panel and loadlayout to it . Very simple, right ?


customview class:
'Custom View class
#Event: ExampleEvent (Value As Int)
#DesignerProperty: Key: BooleanExample, DisplayName: Boolean Example, FieldType: Boolean, DefaultValue: True, Description: Example of a boolean property.
#DesignerProperty: Key: IntExample, DisplayName: Int Example, FieldType: Int, DefaultValue: 10, MinRange: 0, MaxRange: 100, Description: Note that MinRange and MaxRange are optional.
#DesignerProperty: Key: StringWithListExample, DisplayName: String With List, FieldType: String, DefaultValue: Sunday, List: Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday
#DesignerProperty: Key: StringExample, DisplayName: String Example, FieldType: String, DefaultValue: Text
#DesignerProperty: Key: ColorExample, DisplayName: Color Example, FieldType: Color, DefaultValue: 0xFFCFDCDC, Description: You can use the built-in color picker to find the color values.
#DesignerProperty: Key: DefaultColorExample, DisplayName: Default Color Example, FieldType: Color, DefaultValue: Null, Description: Setting the default value to Null means that a nullable field will be displayed.
Sub Class_Globals
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Private mBase As Panel
    Private Const DefaultColorConstant As Int = -984833 'ignore
    
    Private sp As ScrollView
    Private spkvarpanel As Panel
    Private airvarpanel As Panel
End Sub

Public Sub Initialize (Callback As Object, EventName As String)
    mEventName = EventName
    mCallBack = Callback
    
    sp.Initialize(1000dip)
    spkvarpanel.Initialize("spkvarpanel")
    spkvarpanel.LoadLayout("newlayout")
    airvarpanel.Initialize("airvarpanel")
    Log("VarPanel initialized")
End Sub

Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
    mBase.AddView(sp,2dip, 2dip, mBase.Width-4dip, mBase.Height-4dip)
    
    Log("Varpanel DesignerCreateView")
End Sub

Public Sub GetBase As Panel
    Return mBase
End Sub


Layout file "newlayout" is completely empty layout, but an exist .bal file
1606811386983.png



But I am getting this exception :

exception code:
Logger connected to:  HUAWEI LIO-L29
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Panel size is unknown. Layout may not be loaded correctly.
Error occurred on line: 26 (VarPanel)
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at gtc.splcalculator.varpanel._initialize(varpanel.java:130)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:61)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at gtc.splcalculator.main._activity_create(main.java:392)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at gtc.splcalculator.main.afterFirstLayout(main.java:105)
    at gtc.splcalculator.main.access$000(main.java:17)
    at gtc.splcalculator.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:900)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:8349)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:44)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    ... 29 more
** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Panel size is unknown. Layout may not be loaded correctly.
Error occurred on line: 26 (VarPanel)
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at gtc.splcalculator.varpanel._initialize(varpanel.java:130)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:61)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at gtc.splcalculator.main._activity_create(main.java:392)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at gtc.splcalculator.main.afterFirstLayout(main.java:105)
    at gtc.splcalculator.main.access$000(main.java:17)
    at gtc.splcalculator.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:900)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:8349)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:44)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    ... 29 more
** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Panel size is unknown. Layout may not be loaded correctly.
Error occurred on line: 26 (VarPanel)
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at gtc.splcalculator.varpanel._initialize(varpanel.java:130)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:61)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at gtc.splcalculator.main._activity_create(main.java:392)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at gtc.splcalculator.main.afterFirstLayout(main.java:105)
    at gtc.splcalculator.main.access$000(main.java:17)
    at gtc.splcalculator.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:900)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:8349)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:44)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    ... 29 more
** Activity (main) Resume **
Service started in the background. Trying to start again in foreground mode.
*** Service (starter) Create ***
** Service (starter) Start **
Service started in foreground mode.
** Activity (main) Create, isFirst = true **
Panel size is unknown. Layout may not be loaded correctly.
Error occurred on line: 26 (VarPanel)
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at gtc.splcalculator.varpanel._initialize(varpanel.java:130)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:61)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at gtc.splcalculator.main._activity_create(main.java:392)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at gtc.splcalculator.main.afterFirstLayout(main.java:105)
    at gtc.splcalculator.main.access$000(main.java:17)
    at gtc.splcalculator.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:900)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:8349)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:44)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    ... 29 more
** Activity (main) Resume **

Of course I browsed this forum threads before posting it :

B4A version : 10.2
Core version : 9.90
XUI version : 2.00
 

rdkartono

Member
Licensed User
I recommend you to use the Custom View (XUI) template. It is better.

This error means that a global view variable has the wrong type. If you can't find it then please upload the project.
well actually, the code i posted here, is a 2 times downgrade.
first time, I use B4XPages (newest), then found this error .
confused, I downgrade my codes to XUI Custom View, but still same error
furiously , I downgrade my codes again to become old stype Custom View (this code), yet still error the same
 

Attachments

  • SPLCalc.zip
    14.3 KB · Views: 32
Upvote 0

rdkartono

Member
Licensed User
You haven't initialized the panels and scrollview. Because they are not declared in the designer you need to initialize them yourself.
Sorry. Forget this rubbish. I obviously haven't woken up properly and my morning tea fix hasn't kicked in properly yet. :confused:
morning tea is not enough caffein , my friend .
double shots espresso should do the job :D
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
You cannot load a layout while another layout is being loaded.

If you want to load a layout in a custom view then it needs to be done like this:
B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
    mBase.AddView(sp,2dip, 2dip, mBase.Width-4dip, mBase.Height-4dip)
    
    Sleep(0)
     'you can load a layout here
End Sub
 
Upvote 0

rdkartono

Member
Licensed User
You cannot load a layout while another layout is being loaded.

If you want to load a layout in a custom view then it needs to be done like this:
B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
    mBase.AddView(sp,2dip, 2dip, mBase.Width-4dip, mBase.Height-4dip)
   
    Sleep(0)
     'you can load a layout here
End Sub

I can confirm this work. Thanks Erel !
 
Upvote 0
Top