Android Question AScheckbox cannot be cast

zed

Active Member
Licensed User
It works fine with a simple checkbox, but with ASCheckbox the types don't match.
An idea ?
B4A:
Private Sub DrawCheckBox
    Dim disty As Int = 20dip
    Dim chkBox(9) As B4XView

    For i = 1 To 8
        Dim chk As ASCheckbox
        chk.Initialize(Me,"chkView")
        chkBox(i) = chk '<--the types don't match
        chkBox(i).Tag = i
      
        pnlCheckBox.AddView(chkBox(i), 10dip, disty, 30dip, 30dip)
        disty = disty + 33dip
    Next
 End Sub

--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Error occurred on line: 459 (Main)
java.lang.ClassCastException: b4a.example.ascheckbox cannot be cast to android.view.View
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:91)
at anywheresoftware.b4a.objects.B4XViewWrapper.setTag(B4XViewWrapper.java:603)
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:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.example.main._drawcheckbox(main.java:1126)
at b4a.example.main._activity_create(main.java:443)
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:157)
at b4a.example.main.afterFirstLayout(main.java:105)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8302)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)
** Activity (main) Resume **
 

Alexander Stolte

Expert
Licensed User
Longtime User
chkBox(i) = chk '<--the types don't match
B4X:
chkBox(i).Tag = chk '<--the types don't match
you forgot the .Tag
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Dim chk As ASCheckbox chk.Initialize(Me,"chkView")
and this way you cant initialize a custom view.
You need the designer properties too and you need to call "DesignerCreateView"
It is better to add the checkbox to a new form and load this form to your panel.
 
Upvote 0

zed

Active Member
Licensed User
Thanks for the answers.
Other elements (label, imageview) are created in the same way.
For questions of ease of alignment with the other elements, I wanted to use the same principle for everything.
It is better to add the checkbox to a new form and load this form to your panel.
Yes of course. I will proceed differently.
THANKS
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Other elements (label, imageview) are created in the same way.
These elements are also native components, which work differently than custom views.They even have other areas in the designer where you can set something.
 
Upvote 0
Top