Android Question Designer object should first be initialised...

Dominik H

Member
Licensed User
Longtime User
This problem only occurs in debug mode, it works perfectly fine in Release mode.

When I try to use loadlayout, I get an error that the imageview inside my layout must first be initialised, but since this is a designer added view, it should not need initialisation, right?

Could it be a number issue? I have 35 small imageviews on there, but this worked in the past where there were only 30.

There's not really any code to show other than I used Panel.LoadLayout("layoutname") (of course replacing Panel and layoutname with the actual names) and this line causes the error.

Here's the stack trace:

Stack Trace:
Error occurred on line: 312 (CardPreview)
java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (ImageView).
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at com.ygoacc.debug.cardpreview._loadlayouts(cardpreview.java:793)
    at com.ygoacc.debug.cardpreview._activity_create(cardpreview.java:549)
    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 com.ygoacc.debug.cardpreview.afterFirstLayout(cardpreview.java:105)
    at com.ygoacc.debug.cardpreview.access$000(cardpreview.java:17)
    at com.ygoacc.debug.cardpreview$WaitForLayout.run(cardpreview.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8016)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
Caused by: java.lang.RuntimeException: Object should first be initialized (ImageView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
 

Dominik H

Member
Licensed User
Longtime User
Is the name in the code the same as in the Designer?
Yes, the names match.
Have a look, if you´re not setting any property related to the ImageView in the code before you load the layout.
I double checked and there is no usage of any ImageViews before this layout is loaded, and as I say, it works as expected in Release mode, so I don't know if I've somehow glitched the debugger out?

The worst thing is, I can't replicate it at all, it works in a small test project just fine, so I think I messed something up for sure.
 
Last edited:
Upvote 0

Dominik H

Member
Licensed User
Longtime User
Without more information it is impossible to give more help.
Post your project, maybe we could find what is going wrong.

The project is huge, I don't think I'd be able to post it, I'll try other workarounds for now, maybe deleting the imageviews and readding them helps, etc.

Just did some tests, I removed the imageviews that were causing the crash, and debug mode worked fine, but then readding them (either via copy paste or via new item) it still crashes immediately... Is there such a thing is too many ImageViews? It just seems odd that after the 30th imageview it crashes.

I've just separated all my imageviews in hopes that this will change anything, but no it's still the same 5 views that cause the crash.
 
Last edited:
Upvote 0

Dominik H

Member
Licensed User
Longtime User
This is the code:
B4X:
Sub Globals
    Private Card_1 As ImageView
    Private Card_2 As ImageView
    Private Card_3 As ImageView
    Private Card_4 As ImageView
    Private Card_5 As ImageView
    Private Card_6 As ImageView
    Private Card_7 As ImageView
    Private Card_8 As ImageView
    Private Card_9 As ImageView
    Private Card_15 As ImageView
    Private Card_16 As ImageView
    Private Card_22 As ImageView
    Private Card_23 As ImageView
    Private Card_30 As ImageView
  
    Private Card_10 As ImageView
    Private Card_11 As ImageView
    Private Card_12 As ImageView
    Private Card_13 As ImageView
    Private Card_14 As ImageView
    Private Card_17 As ImageView
    Private Card_18 As ImageView
    Private Card_19 As ImageView
    Private Card_24 As ImageView
    Private Card_31 As ImageView
    Private Card_32 As ImageView
    Private Card_33 As ImageView
  
    Private Card_20 As ImageView
    Private Card_21 As ImageView
    Private Card_25 As ImageView
    Private Card_26 As ImageView
    Private Card_27 As ImageView
    Private Card_28 As ImageView
    Private Card_29 As ImageView
    Private Card_34 As ImageView
    Private Card_35 As ImageView
  
    Private selectorImg As ImageView
End Sub

Sub Activity_Create
    Panel1.Panel.LoadLayout("Preview")
    cv.Initialize("cv")
    Panel1.Panel.AddView(cv, 4%x, template.Height + 16dip, 100%x - 4dip, 2000dip)
    cv.LoadLayout("CardsList")
End Sub

Card 31-33 are what cause the crash, 34 and 35 don't seem to be affected.

At this point I'm considering just dealing with the nuisance of not having debug mode and moving on, but surely there's something I can do.

I attached a screenshot of the designer view below:

Untitled.png
 
Upvote 0

Dominik H

Member
Licensed User
Longtime User
Hang on I'm onto something here @klaus :
B4X:
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.DynamicBuilder.build(DynamicBuilder.java:38)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:349)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:453)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:148)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at com.ygoacc.debug.cardpreview._loadlayouts(cardpreview.java:668)
    at com.ygoacc.debug.cardpreview._activity_create(cardpreview.java:550)
    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 com.ygoacc.debug.cardpreview.afterFirstLayout(cardpreview.java:105)
    at com.ygoacc.debug.cardpreview.access$000(cardpreview.java:17)
    at com.ygoacc.debug.cardpreview$WaitForLayout.run(cardpreview.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8016)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: /data/user/0/com.ygoacc.debug/files/virtual_assets/ra_1-box_preview.jpg: open failed: ENOENT (No such file or directory)
    at anywheresoftware.b4a.objects.ImageViewWrapper.setImage(ImageViewWrapper.java:103)
    at anywheresoftware.b4a.objects.ImageViewWrapper.build(ImageViewWrapper.java:124)
    ... 24 more
Caused by: java.io.FileNotFoundException: /data/user/0/com.ygoacc.debug/files/virtual_assets/ra_1-box_preview.jpg: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:496)
    at java.io.FileInputStream.<init>(FileInputStream.java:159)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:204)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:516)
    at anywheresoftware.b4a.objects.drawable.BitmapDrawable.build(BitmapDrawable.java:69)
    at anywheresoftware.b4a.objects.ImageViewWrapper.setImage(ImageViewWrapper.java:101)
    ... 25 more
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Linux.open(Native Method)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
    at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7893)
    at libcore.io.IoBridge.open(IoBridge.java:482)
    ... 30 more
Error occurred on line: 236 (CardPreview)
java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (ImageView).
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at com.ygoacc.debug.cardpreview._loadlayouts(cardpreview.java:668)
    at com.ygoacc.debug.cardpreview._activity_create(cardpreview.java:550)
    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 com.ygoacc.debug.cardpreview.afterFirstLayout(cardpreview.java:105)
    at com.ygoacc.debug.cardpreview.access$000(cardpreview.java:17)
    at com.ygoacc.debug.cardpreview$WaitForLayout.run(cardpreview.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8016)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
Caused by: java.lang.RuntimeException: Object should first be initialized (ImageView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.ViewWrapper.innerInitialize(ViewWrapper.java:73)
    at anywheresoftware.b4a.objects.ImageViewWrapper.innerInitialize(ImageViewWrapper.java:36)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:434)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:453)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:148)
    ... 19 more
** Activity (cardpreview) Resume **

It's not finding the Assets which are clearly in the files folder. I've pressed sync but this didn't solve the issue. Is there any way to copy them over manually?
 
Upvote 0
Top