Android Question Error event TextChanged in xCustomListView

ermales

Member
Licensed User
When I add a item in xCustomListView I get this error

java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at b4a.example3.customlistview._getitemfromview(customlistview.java:413)
at com.limelogic.kimerapp.formagregaracompra._txtitemprecio_textchanged(formagregaracompra.java:4181)
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 anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.objects.EditTextWrapper$1.afterTextChanged(EditTextWrapper.java:83)
at android.widget.TextView.sendAfterTextChanged(TextView.java:9622)
at android.widget.TextView.setText(TextView.java:5513)
at android.widget.TextView.setText(TextView.java:5360)
at android.widget.EditText.setText(EditText.java:113)
at android.widget.TextView.setText(TextView.java:5317)
at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:39)
at anywheresoftware.b4a.objects.B4XViewWrapper.setText(B4XViewWrapper.java:208)
at com.limelogic.kimerapp.formagregaracompra._createlistitemlista(formagregaracompra.java:2386)
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 anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

In the event I have this code

Event TextChanged:
Sub txtItemP_TextChanged (Old As String, New As String)
    Dim txt As EditText
    txt = Sender
    
    Dim index As Int = clvLista.GetItemFromView(Sender)     <------ I get the error on this line
    Dim pnl As B4XView = clvLista.GetPanel(index)
    Dim pan1 As B4XView = pnl.GetView(0)
    Dim lblcan As B4XView = pan1.GetView(3)
    Dim lbltot As B4XView = pan1.GetView(6)
    Dim txtPD As B4XView = pan1.GetView(9)
    
...

What is my error?

Please help me....
 

mangojack

Expert
Licensed User
Longtime User
What is my error?

Your Thread Title indicates the error occurs in the TextChanged event ... but I do Not get any error running your code with a mock layout ..

but then you say the error occurs when you add an item to the xCLV .
When I add a item in xCustomListView I get this error


It might be easier to upload your project ... or a small sample demonstrating the problem.



also note ... if pan1 is declared as B4XView then there is no need to re-declare the panel views if you are want to modify their properties ..
for example ...
B4X:
Sub txtItemP_TextChanged (Old As String, New As String)
    'Dim txt As EditText     "not needed   ... do not attempt to edit txt.Text or you will get error !
    'txt = Sender

    Dim index As Int = clv2.GetItemFromView(Sender)    ' <------ I do NOT get the error on this line
    Dim pnl As B4XView = clv2.GetPanel(index)
    Dim pan1 As B4XView = pnl.GetView(0)
    pan1.GetView(3).Text = "ABC"
    pan1.GetView(6).Text = "123"
    pan1.GetView(9).EditTextHint = "New Hint"  'unsure what you are planning to do with this edittext ?

End Sub
 
Last edited:
Upvote 0

ermales

Member
Licensed User
Your Thread Title indicates the error occurs in the TextChanged event ... but I do Not get any error running your code with a mock layout ..

but then you say the error occurs when you add an item to the xCLV .



It might be easier to upload your project ... or a small sample demonstrating the problem.



also note ... if pan1 is declared as B4XView then there is no need to re-declare the panel views if you are want to modify their properties ..
for example ...
B4X:
Sub txtItemP_TextChanged (Old As String, New As String)
    'Dim txt As EditText     "not needed   ... do not attempt to edit txt.Text or you will get error !
    'txt = Sender

    Dim index As Int = clv2.GetItemFromView(Sender)    ' <------ I do NOT get the error on this line
    Dim pnl As B4XView = clv2.GetPanel(index)
    Dim pan1 As B4XView = pnl.GetView(0)
    pan1.GetView(3).Text = "ABC"
    pan1.GetView(6).Text = "123"
    pan1.GetView(9).EditTextHint = "New Hint"  'unsure what you are planning to do with this edittext ?

End Sub


Hello, thanks for your help, I have uploaded a small example where you can see the error....
 

Attachments

  • xCustomEdit.zip
    10.9 KB · Views: 218
Upvote 0

mangojack

Expert
Licensed User
Longtime User
1. The Main Error was caused by trying to populate txtPre in the CreateListItem sub.
This was then raising the TextChanged event before the Item is loaded to the xCLV. This code was moved after the xCLV item is loaded.

2. You should maybe change the input Type for txtPre to DECIMAL_NUMBERS (Designer > Text Properties > Input Type)

3. I have put a basic error catch in the TextChanged event .. but it might need more / formatting control ?

4. The code was moved to Activity_Create. There was an error/warning when run in Debug mode only. (see comment)

I have commented other possible changes / suggestions.
 

Attachments

  • xCustomEdit2.zip
    11.3 KB · Views: 208
Upvote 0
Top