Android Question B4XFloatTextField _TextChanged view not initialised error

rleiman

Well-Known Member
Licensed User
Longtime User
Greetings,

In my logs I get an error telling me to initialise the view. I thought that loading a layout was enough to initialise the text view but it looks like I may need to use an initialise statement in the TextChanged sub routine because if I comment out the sub routine there is no crashing the app.

Code that loads the layout the text view is in:
B4X:
Sub ButtonSongDetails_Click
   
    ' Make views slide down out of site.
    '-----------------------------------
    clvSongList.Clear
       
    PanelSongList.SetLayoutAnimated(300, 0, Activity.Height, Activity.Width, _
        Activity.Height)      

    ButtonBackToMenu.SetLayoutAnimated(300, 0, Activity.Height, Activity.Width, _
        Activity.Height)
       
    ButtonClearSong.SetLayoutAnimated(300, 0, Activity.Height, Activity.Width, _
        Activity.Height)
       
    ButtonSongDetails.SetLayoutAnimated(300, 0, Activity.Height, Activity.Width, _
        Activity.Height)

    Activity.LoadLayout("SongDetails")
End Sub

Code used to hide the hint when text is entered into the text field:
B4X:
Sub b4xfloattextfieldsongtitle_TextChanged (Old As String, New As String)
       b4xfloattextfieldsongtitle.mBase.GetView(1).Visible = (New.Trim.Length = 0)
End Sub

The view is also defined from the designer as:
B4X:
Private B4XFloatTextFieldSongTitle As B4XFloatTextField

The logs showing the error:
B4X:
main_b4xfloattextfieldsongtitle_textchanged (java line: 431)
java.lang.RuntimeException: Object should first be initialized (View).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.B4XViewWrapper.GetView(B4XViewWrapper.java:317)
    at b4a.natures.song.main._b4xfloattextfieldsongtitle_textchanged(main.java:431)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1082)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:1045)
    at b4a.natures.song.b4xfloattextfield._tf_textchanged(b4xfloattextfield.java:755)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.objects.EditTextWrapper$1.afterTextChanged(EditTextWrapper.java:83)
    at android.widget.TextView.sendAfterTextChanged(TextView.java:11652)
    at android.widget.TextView.setText(TextView.java:6839)
    at android.widget.TextView.setText(TextView.java:6630)
    at android.widget.EditText.setText(EditText.java:140)
    at android.widget.TextView.setText(TextView.java:6582)
    at android.widget.TextView.setTransformationMethod(TextView.java:2870)
    at android.widget.TextView.applySingleLine(TextView.java:11307)
    at android.widget.TextView.setSingleLine(TextView.java:11281)
    at anywheresoftware.b4a.objects.EditTextWrapper.setSingleLine(EditTextWrapper.java:140)

The layout with the text view:
Screenshot 2020-11-20 at 11.32.21.png
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
it looks like I may need to use an initialise statement in the TextChanged sub routine because if I comment out the sub routine there is no crashing the app.
No, I don; t think so. Your b4xfloattextfieldsongtitle_TextChanged routine looks correct. The problem is somewhere else. Something is still not kosher. I am not sure if the culprit code is shown in your post.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
First I will try using a normal EditText view and see if I get an error by changing the text property of the view.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
No, I don; t think so. Your b4xfloattextfieldsongtitle_TextChanged routine looks correct. The problem is somewhere else. Something is still not kosher. I am not sure if the culprit code is shown in your post.
Thanks for the reply. I added a regular EditText view and there was no crash or error. The code mirrors the text I entered into the EditText view onto the b4xfloattextfield view without any crashing. Looks like I might have to skip using the b4xfloattextfield view even though I like what it's capable of doing.

B4X:
Sub B4XFloatTextFieldSongTitle_TextChanged (Old As String, New As String)

'    Log(B4XFloatTextFieldSongTitle.Text)

'    Log(B4XFloatTextFieldSongTitle.mBase.GetView(0).Visible)

'    If New.Trim.Length = 0 Then
'        B4XFloatTextFieldSongTitle.mBase.GetView(1).Visible = True
'    Else
'        B4XFloatTextFieldSongTitle.mBase.GetView(1).Visible = False
'    End If
'    B4XFloatTextFieldSongTitle.mBase.GetView(1).Visible = New.Trim.Length = 0
End Sub

Sub EditText1_TextChanged (Old As String, New As String)
    B4XFloatTextFieldSongTitle.Text = New
End Sub

Screenshot_20201120-154119.jpg
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
This code is not correct. you are putting EditText1 in one line and B4XFloatTextFieldSongTitle on the other
Hi Mahares,

The code I inserted into the post was only to show that I had commented out the old coding that was in the B4XFloatTextFieldSongTitle view and that I was able to successfully able to copy the text from the EditText view into the B4XFloatTextFieldSongTitle view shown in the screen shot.

It shows that both views are initialised, otherwise I think the app would crash. As soon as I put coding into the TextChanged subroutine, the app crashes.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
It shows that both views are initialised, otherwise I think the app would crash.
Yes. I have a project with a B4XFLoatEditText where I hide the hint and it is exactly like the code you posted. It worked for me. As you know the B4XFloat is stored in its tag. Sometimes it is a matter of inserting a Sleep(0) after loading the layout, although I did not have that in my project and it worked. If you can get it to work, it is a good XUI View to use. I would not give up on the float yet.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Yes. I have a project with a B4XFLoatEditText where I hide the hint and it is exactly like the code you posted. It worked for me. As you know the B4XFloat is stored in its tag. Sometimes it is a matter of inserting a Sleep(0) after loading the layout, although I did not have that in my project and it worked. If you can get it to work, it is a good XUI View to use. I would not give up on the float yet.
For now I will most likely use the B4XFloatTextFieldSongTitle as long as I don't use the TextChange handler and changed the hint so it will look more like a label for the user. I really like that view.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I really like that view.
Usually when I have a nagging problem like that I create a skeleton project and see how it works. Here is a complete working project, you can check to see if you still have a problem. I use XUI Views lib 2.41

B4X:
Sub Globals
    Private B4XFloatTextField2 As B4XFloatTextField   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layoutnew")   'has B4XFloatTextField2
End Sub

'To hide hint text
Sub B4XFloatTextField2_TextChanged (Old As String, New As String)
    B4XFloatTextField2.mBase.GetView(1).Visible = (New.Trim.Length = 0)
End Sub
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Usually when I have a nagging problem like that I create a skeleton project and see how it works. Here is a complete working project, you can check to see if you still have a problem. I use XUI Views lib 2.41

B4X:
Sub Globals
    Private B4XFloatTextField2 As B4XFloatTextField  
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layoutnew")   'has B4XFloatTextField2
End Sub

'To hide hint text
Sub B4XFloatTextField2_TextChanged (Old As String, New As String)
    B4XFloatTextField2.mBase.GetView(1).Visible = (New.Trim.Length = 0)
End Sub
Your code is just like mine. Do you also have an xCLV in the same layout? Mine has the xCLV, ImageViews, B4XProgressBar, B4XSeekBar and Labels.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Do you also have an xCLV in the same layout
The only reason I posted that code is to demonstrate that the B4XFloattextchanged event works. I did not have an xCLV on mine, but I went ahead added an xCLV to the layout and it still works. As long as all the xCLV and other views code is not related to the B4Xfloat, then there should not be a problem. But if all the views are related by code somewhere in your project, then the problem may be there somewhere.. As klaus always say: 'there is not enough information to help, please create a small project that reproduces the issue and export to forum'.
I am sure someone will figure it out and help you.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
The only reason I posted that code is to demonstrate that the B4XFloattextchanged event works. I did not have an xCLV on mine, but I went ahead added an xCLV to the layout and it still works. As long as all the xCLV and other views code is not related to the B4Xfloat, then there should not be a problem. But if all the views are related by code somewhere in your project, then the problem may be there somewhere.. As klaus always say: 'there is not enough information to help, please create a small project that reproduces the issue and export to forum'.
I am sure someone will figure it out and help you.
We are too far into the project to post a small project but will when the project is complete.

Thanks so much for all the help you gave us in the past. ?

A lot of the help from the B4X community also went into this app a radio station located in Malaysia and I developed. It's for the visually impaired community over there.

The is the Radio Streaming app. It's on Google Play.
 
Last edited:
Upvote 0
Top