Android Question Error with view type loading layout, but view does not exist

Martincg

Member
Licensed User
Longtime User
When my app starts i get an error on the line that says Activity.Loadlayout(...
The error messages start like this

java.lang.RuntimeException: java.lang.RuntimeException: Field label3 was declared with the wrong type.

There is no label3 in the design, the single design script or the in the bas program files. (Ctrl F Label3 finds nothing)

Otherwise the app runs as expected.
I am using an AutoTextSizeLabel. I cannot see how to make this invisible or to move it off screen which would do the same job.

How do I isolate the error?
How do I set the position or visibility of an AutoTextSizeLabel?
 

klaus

Expert
Licensed User
Longtime User
1. Have you tried to define a new layout and remove the current one?
Or you should post your project as a zip file, so we can see what you have done and how.

2. You can add the code below in the AutoTextSizeLabel class.
This adds the Visible propety.
B4X:
'Gets or sets the Visible property
Public Sub getVisible As Boolean
    Return mLbl.Visible
End Sub

Public Sub setVisible(Visible As Boolean)
    mLbl.Visible = Visible
End Sub
And in the Main code:
AutoTextSizeLabel1.Visible = False
 
Upvote 0

Martincg

Member
Licensed User
Longtime User
This error seems to have been caused by having 2 copies of the designer open.
I don't see why it caused the error since neither one had a label3 but who cares?

Thanks for your answer Klaus.

I'll add the code to the class as you showed. It makes sense to me buT I didn't know how to do that myself.
Would the same approach work for Top and Left say?
 
Upvote 0

Martincg

Member
Licensed User
Longtime User
Yes Thanks Klaus.
I can now move the AutoTextSizeLabel1 around and make it invisible it not. I feel like I can conquer the world.
 
Upvote 0

Martincg

Member
Licensed User
Longtime User
But if I try this in the custom view class module it doesn't work.
B4X:
Sub CenterText  'can't get this to work yet, or setCenterText
   Dim ss As String
   
   ss = mLbl.Text.Trim
   Do While cvs.MeasureStringWidth(" " & ss & " ", mLbl.Typeface, mLbl.textsize) < mLbl.Width
       ss = " " & ss & " " 'but only really any good for monospace font
   Loop
   
   mLbl.Text = ss
End Sub
Where can I find out how to do this? I've seen a post where Erel talks about Par maps which means nothing to me, though I assume parameter maps, which still means nothing.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What exactly do you want to do?
In your code you try to add an empty character at each end, what for?
If want your text centered in the Label, I suppose horizontally, just set Horizontal Alignment to CENTRER_HORIZONTAL in the Designer.
 
Upvote 0

Martincg

Member
Licensed User
Longtime User
There is no CENTER_HOTIZONTAL for the AutoTextSizeLabel so I am trying to add it like I did for Visible, left, top etc

Maybe in the class module I could set the horizontal alignment,but I don't know how to to do it. If I add a sub in the class it doesn't appear as a method or property for the class. So I need to learn. Sub setWidth for example shows as "width" method or property for the class but "sub something" doesn't nor does "sub setSomething". Guessing often fails I've found.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
I set it here:

upload_2019-10-9_19-53-46.png


I tested this in Erel's demo program, before sending post #7.
 
Upvote 0

Martincg

Member
Licensed User
Longtime User
Yes, you're right of course.
My apologies Klaus for wasting your time, I must have been looking at some other view which didn't have that option.
Thank you.
 
Upvote 0
Top