Error Msg, but don't know why

sterlingy

Active Member
Licensed User
Longtime User
I have a panel made in the designer. Attached to it are 9 ImageViews

In my code, I have subroutine the detects a click on one of the ImageViews. This works. But determining which ImageView is clicked results in an error, "Class Exception," and I don't know why:

B4X:
Sub pnlCameraEffect_Click
   Dim cameraEffectChoice As ImageView
   
   cameraEffectChoice = Sender
   
   Select cameraEffectChoice.Tag
      Case "0"
         camera1.ColourEffect = "NONE"
         pnlCameraEffect.Visible = False
      Case "1"
         camera1.ColourEffect = "AQUA"
         pnlCameraEffect.Visible = False
      Case "2"
         camera1.ColourEffect = "BLACKBOARD"
         pnlCameraEffect.Visible = False
      Case "3"
         camera1.ColourEffect = "MONO"
         pnlCameraEffect.Visible = False
      Case "4"
         camera1.ColourEffect = "NEGITIVE"
         pnlCameraEffect.Visible = False
      Case "5"
         camera1.ColourEffect = "POSTERIZE"
         pnlCameraEffect.Visible = False
      Case "6"
         camera1.ColourEffect = "SEPIA"
         pnlCameraEffect.Visible = False
      Case "7"
         camera1.ColourEffect = "SOLARIZE"
         pnlCameraEffect.Visible = False
      Case "8"
         camera1.ColourEffect = "WHITEBOARD"
         pnlCameraEffect.Visible = False
      End Select
End Sub
 

sterlingy

Active Member
Licensed User
Longtime User
Hi Klaus,

I can't post the project without spending a lot of time hiding Server information and passwords.

The code stops at "cameraEffectChoice = Sender"

I should correct my previous message, the error says: "ClassCastException"

-Sterling
 
Upvote 0

Woinowski

Active Member
Licensed User
Longtime User
Guess: Click comes from Panel

Hi,

your method is called pnlCameraEffect_Click. Could it be that the click event is not raised by the ImageViews, but by the panel they contain?

To check this, add this code at the beginning of the method:

try
Dim p as Panel
p = Panel
MessBox("It's a panel", "That's it")
return
catch
MasgBox(LastException.Message, "Not a panel")
end try

If you get "It's a panel" then you need to wire the panel to a different event.
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
Here's the actual error message from the debugger:

java.lang.ClassCastException: anywheresoftware.b4a.BALayout

-Sterling
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
try
Dim p as Panel
p = Panel
MessBox("It's a panel", "That's it")
return
catch
MasgBox(LastException.Message, "Not a panel")
end try

I dropped your code into mine, but is has errors

B4X:
p = Panel

Error description: Undeclared variable 'panel' is used before it was assigned any value.

-Sterling :(
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
Just a guess (same idea as Woinowski):

from the name of the event, it might be that this is an event for the panel click (and NOT for the imageview click), hence the sender is a panel and you try to assign it to an imageview.
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
Thanks to all who chimed in.

The problem was tat the ImageViews needed to be part of the same EVENT.

The moral of the story is don't code near midnight!

-Sterling :sign0161:
 
Upvote 0

Woinowski

Active Member
Licensed User
Longtime User
I dropped your code into mine, but is has errors

B4X:
p = Panel

Error description: Undeclared variable 'panel' is used before it was assigned any value.


-Sterling :(
That was a typo: p = Sender :)
 
Upvote 0
Top