Timer being caught as sender in a panel click event

Mickster

Active Member
Licensed User
Longtime User
Hey Guys,

Yesterday I added FTP functionality to my app and it caused strange behavior for existing, proven code.

The app behaves normally until the FTP communication is initilised and ended. After this, a panel click even I have raises an error claiming that a timer cannot be cast as a panel.

B4X:
java.lang.ClassCastException: anywheresoftware.b4a.objects.Timer cannot be cast to android.view.ViewGroup

This is the routine that causes the error:

B4X:
   If loadedfile = "" Then
      CallPromptBox("You must save your program to take pictures. Save now?", False, "ForceSave", False)
      Return
   End If
   If QWERTYPanelBackground.visible = True Then txtOffsetsCommentBox_EnterPressed
   Dim panel1 As Panel
   If Sender Is Panel Then 
      panel1 = Sender
   Else
      Return
   End If
   intCameraSelected = panel1.Tag

I added the IF statement regarding the nature of the sender to see if I could quickly patch the bug. This prevented the errors, but forces me to double click (in quick succession) the panel in order to pass the correct sender.

Anyone have any thoughts?

Thanks
 

Mickster

Active Member
Licensed User
Longtime User
I think it's worth mentioning that I have other areas of the app that rely on sender to identify a clicked panel and they operate fine after the FTP communication...pretty spooky stuff!

EDIT

Also worth adding that a debug message isn't raised when this error occurs in debug mode. It's always a java error. Possible bug in the Net library?
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
do you have any other views behind your panel? if yes, set panel_touch to return true,in order to consume the event because clicking may be passed to another control behind the panel, causing problems. just a thought
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
Thanks for the idea, but it didn't work.

There are no other views behind the panel, also, it works perfectly fine before we use the FTP. I don't even know where this timer is coming from :)
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
Just remembered another bug that happens after we use FTP. We have a panel that is animated from below the screen into view. After the communication, the animation doesn't occur and the panel doesn't appear.
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
Unfortunately the app we're working on is too big to send. I'm going to try and recreate the issue in a smaller app, but I feel that if the issue were that simple, someone would have discovered it a while ago. Since our program is so big, the problem may be a combination of conflicts from multiple libraries.

I'll let you know if I find anything.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Just remembered another bug that happens after we use FTP. We have a panel that is animated from below the screen into view. After the communication, the animation doesn't occur and the panel doesn't appear.
Is this animation using a timer perhaps?
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
The animation is a translation from the animations library.

I couldn't repeat the issue in a new app, but I've discovered something about the issue in the main app. I logged the interval of the sender timer and discovered that it's a real timer I have running. For test purposes I disabled this timer and tried again. This time the program tripped on a DIFFERENT timer...
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
No naming issue. The program has been running with these features for a good three months. The glitch only started after we implemented the FTP yesterday, and the weirdest part is that the glitch only occurs if the FTP has been accessed (access to the FTP is initialised by the user).
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Unless there is something I'm not aware of or something possibly named the same in the FTP code, the only way for one event to fire another event is to be named the same like:

You have a panel named or initialized like panel1.initialize("panel1") then later use a timer and call timer.initialize("panel1"). Even then though the timer event would be called panel1_tick and not click, so unless there is a spelling error somewhere.

May want to search for the name of the panel click sub and make sure something isn't calling it direct somehow. Posting the names of the panels and timers may be helpful too and then we can see if there is a conflict somehow with an internal keyword or something in the FTP library and one of the names. (Variable names and the Event Name in the Designer or name given to the Initialize function if that is used)
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
As the program is really big, we give all our objects long specific names.

B4X:
   For x = 0 To 2
      pnlOffsetsImageHolder(x).Initialize("pnlOffsetsImageHolder")
      pnlOffsetsImageHolder(x).Color = Colors.LightGray
      pnlOffsetsImageHolder(x).Tag = (x+1)
   Next

This is the initialisation of the panel that causes the error. All three panels have the same event name, which is why I use sender.

B4X:
Sub pnlOffsetsImageHolder_Click

   If loadedfile = "" Then
      CallPromptBox("You must save your program to take pictures. Save now?", False, "ForceSave", False)
      Return
   End If
   If QWERTYPanelBackground.visible = True Then txtOffsetsCommentBox_EnterPressed
   Dim panel1 As Panel
   panel1.Initialize("")
   If Sender Is Timer Then
      Dim tim As Timer
      tim = Sender
      Log(tim.Interval)
   Else If Sender Is Panel Then
      panel1 = Sender
   End If
   intCameraSelected = panel1.Tag
   
   If pnlOffsetsImageHolder(intCameraSelected-1).GetView(0).IsInitialized Then
   
      SetCamera
      
      
   Else
      pnlOffsetsImageHolder(0).Enabled = False
      pnlOffsetsImageHolder(1).Enabled = False
      pnlOffsetsImageHolder(2).Enabled = False
      DoEvents
      Dim PressHold As Label
      PressHold.Initialize("PressHold")
      PressHold.Text = "Hold to delete picture."
      PressHold.TextSize = 20
      PressHold.TextColor = Colors.White
      PressHold.Color = Colors.Black
      pnlOffsetsImageHolder(intCameraSelected-1).AddView(PressHold,0, 0, pnlOffsetsImageHolder(intCameraSelected-1).Width, pnlOffsetsImageHolder(intCameraSelected-1).Height)
      PressHold.Gravity = Gravity.CENTER
      PressHold.BringToFront
      PressHold.Visible = True
      
      
      Dim FadeInOut As Animation
      FadeInOut.InitializeAlpha("FadeInOut", 0, 1)
      FadeInOut.RepeatMode = FadeInOut.REPEAT_REVERSE
      FadeInOut.RepeatCount = 1
      FadeInOut.Duration = 1000
      FadeInOut.Start(PressHold)
      
   End If

This is the routine for the click event. Again, the IF statement at the top is to catch out the Timer. I used it to find out details and figure out which Timer I was dealing with.

B4X:
Sub BlueToothConnectedTimer_Tick

   If Connected Then 
      BlueToothConnect.Visible = False
      btnBTNotConnected.Visible = False
      BlueToothDownload.Visible = True
   Else
      If blnTableEdit = False Then BlueToothConnect.Visible = True
      btnBTNotConnected.Visible = True
      BlueToothDownload.Visible = False
   End If
   
   BlueToothTimeout = BlueToothTimeout + 1
   If BlueToothTransTimer.Enabled = False Then BlueToothTimeout = 0
   If BlueToothTimeout = 10 Then 
      Connected = False
      AStreams.Close
      Serial1.Disconnect
      
      If ManualJogPanel.Visible = True OR MachineParameters.Visible = True Then
         CallAlertBox("Connection to the machine has been lost", False)
         YBCTable_Button_Click
      End If
      
   End If
   
End Sub

This is the tick routine for the Timer that initially caused the disruption, however as I mentioned earlier, once this Timer is disabled, a different Timer disrupts the routine instead.

I'm starting to think this may be a one off issue. Perhaps some small glitch from upgrading b4a a few times or a glitch with SVN or something. If I can't find a solution here, I'll try run the program in a fresh b4a file.
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
The FTP code doesn't really have anything to do with this stuff. The FTP takes a bunch of files that are already in the file system and uploads them. The panel that is causing the issue initialises a the camera. Also, the timers that disrupt the program have nothing to do with this panel!

I tried recreating the program in a new b4a file but unfortunately that didn't fix the issue either. Really don't know what to do here...
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Since I think that your problem is mainly the double-click instead of a single click, as a workaround until the real cause of the problem is found, I would suggest a bit different initialization of your panels:

B4X:
pnlOffsetsImageHolder(x).Initialize("pnlOffsetsImageHolder" & x)
This way, you simply create 3 different click events, then you can call the original routine with setting a parameter pointing to the right panel, as for example:
B4X:
sub pnlOffsetsImageHolder0_click
pnlOffsetsImageHolderOld(0)
end sub

sub pnlOffsetsImageHolderOld(whichPanel as int)
end sub

Just a thought...
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
Thanks for the idea, it actually worked.

There are still a number of glitches caused that can't be as easily patched, though. I don't think we're gonna get anywhere until I can recreate this and actually show you the problem :(

EDIT: Well it stopped working already, what a bummer. Guess that just goes to show the total weirdness of this problem.

2ND EDIT: Okay, looks like I found what was causing the issue. I was accidentally calling a routine on the click event. The best I can figure is that calling this routine was too taxing for the tablet (If that is the case...wow) and generally caused a meltdown. I can't explain the timers, I can't explain the animated panel and I can't explain the double click. I know, my explanation is lacking somewhat... :)

Thanks for your help!
 
Last edited:
Upvote 0
Top