Android Question custom view error during release build, not debug

RichyK68

Active Member
Licensed User
Longtime User
Hi,

When I'm running and testing in Debug mode everything works fine. When I build to release I get this:

** Activity (review) Create, isFirst = true **
starrating_designercreateview (java line: 174)
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
at richkidsoftware.myapp.starrating._designercreateview(starrating.java:174)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:67)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
at richkidsoftware.myapp.review._activity_create(review.java:372)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at richkidsoftware.myapp.review.afterFirstLayout(review.java:102)
at richkidsoftware.myapp.review.access$000(review.java:17)
at richkidsoftware.myapp.review$WaitForLayout.run(review.java:80)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
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:158)
... 20 more

It is due to the custom view I am using on the layout.

What am I doing wrong?

Thanks,

Richard
 

RichyK68

Active Member
Licensed User
Longtime User
Hi,

Sure thing! I just knocked this up in a couple of minutes. Works in debug, crashes in release.

Maybe I'm doing something wrong ...

Richard
 

Attachments

  • customviewtest.zip
    9.5 KB · Views: 232
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The problem is here:
B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
   mBase = Base
   Base.LoadLayout("MyCustomView")
       
End Sub
You cannot load a layout file while the current layout file is loaded. The solution is simple.
Change it to:
B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
   mBase = Base
   Sleep(0)
   Base.LoadLayout("MyCustomView")
End Sub
This way the second layout will be loaded after the first one completed.
 
Upvote 0

RichyK68

Active Member
Licensed User
Longtime User
Hi Erel, thanks for the reply, which library would Sleep be in? I currently get:

B4A version: 6.31
Parsing code. Error
Error parsing program.
Error description: Undeclared variable 'sleep' is used before it was assigned any value.
Occurred on line: 23 (MyCustomView)
Sleep(0)

Richard
 
Upvote 0
Top