Android Question java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.EditText

LéonE

Member
Licensed User
Longtime User
I get the error as written in the title.
I have a scrollview and panel as for the example from Klaus "ScrollViewBigPanel".
in this scrollview i create buttons with following code:
B4X:
For t= 1 to 100

But(t).Initialize("ButCL")
But(t).Text=t
But(t).Tag=t
scrview1.Panel.AddView(But(t),Q,Y,80dip,80dip)

next

now the ButCL_Click gives me the above error. Code is

B4X:
Sub ButCL_Click
    Dim tJN As Int
    Dim Send As EditText
    Send.Initialize ("")
    DoEvents
    Send = Sender
    DoEvents

    tJN=Msgbox2(Send.text ,"","Yes","","No",Null)
    If tJN=-1 Then
        'do something
 
    End If
End Sub

i have put in several doevents but also they are not working
when i put in a break and go on than no error is given and i can go on.
if i start the app for the first time NOT i get the error until ONES i put in the break.

had someone this error before?
thanks for any help.
Léone

the whole error looks like this
Error occurred on line: 75 (main)
java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.EditText
at Kelner.le.main._butcl_click(main.java:427)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:305)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:162)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
at android.view.View.performClick(View.java:4204)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5048)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:675)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Pause, UserClosed = true **
GC_CONCURRENT freed 410K, 21% free 2848K/3584K, paused 8ms+2ms, total 33ms
 

LéonE

Member
Licensed User
Longtime User
Sorry NJDude, makes no difference.
thanks anyway. loading and starting again app exits with same error.
 
Upvote 0

LéonE

Member
Licensed User
Longtime User
I figured it out!...
Send should be button
so:
dim send as button
send = sender
var = send.text

this works.
 
Upvote 0
Top