Panel Click Event uncaught exception

Penko

Active Member
Licensed User
Longtime User
Hello all and Erel in particular.

Sorry if the thread title is tricky, I just wanted to say my logic is inside a panel click event. It's not relayed to the panel clicking at all, it might happen anywhere else. Feel free to rename.

I am writing this to report for an uncaught exception by B4A which causes Force Close.

The code segment is:
B4X:
Sub pnll_Click

Dim thePanel As Panel : thePanel = Sender

Dim theData As tProductCategory : theData = thePanel.Tag

zCommon.LogT("pnll_Click() theData = " & theData, "")

If(came_from <> Null) Then
   selectorGetBack(theData) ' maybe here 1
   came_from = Null ' maybe here 2
   selectorBanList.Clear ' maybe here 3
   Activity.Finish
End If

End Sub

I believe the error is somewhere between "maybe 1" and "maybe 3" because if they are commented out, it works. Also, this works perfectly if I use it in a "Picker" mode. However, this Activity is also being started not for a result and that's why I have to check whether the came_from object is Null because this controls whether to return the result or not.

My second question, what is the best way to check whether a certain object is NOT Null?
The keyword "Is" works but I didn't find "Is Not". It's not always useful to use "Is" and put the other code in "Else".

I almost forgot, the exception is:
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Object


at anywheresoftware.b4a.keywords.Common$4.run(Common.java:884)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.lang.Object
at anywheresoftware.b4a.keywords.Common.getComponentBA(Common.java:909)
at anywheresoftware.b4a.keywords.Common.access$0(Common.java:899)
at anywheresoftware.b4a.keywords.Common$4.run(Common.java:833)
... 9 more
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
Not an expert, but I'm a bit afraid with null handling. Did you try to set your variable to something that can represent "your activity not giving back a result", as for example came_from="null". I thing string handling wouldn't produce this error.
I'll give you another example, which demonstrates a problem caused by usage of null:
B4X:
Dim a As String 
a=Null
If a=Null Then
Msgbox("null","ok")
Else
Msgbox ("not null","ok")
End If
Msgbox("a=" & a,"ok")
As you can see, even if we set a to null, in reality, probably due to the string declaration, a is in fact "null".
I don't know if these notes are helpful.

'is not null', would be the same as 'not(is null)' by the way.
 
Upvote 0

Penko

Active Member
Licensed User
Longtime User
Thank you, you always start struggling and try to help.

In fact, everything worked due to the fact it was implemented with strings. Then, Erel advised me to use Object in order to get access to the "Me" keyword and thus not have to write the Activity name with each call.

However, in certain cases, I want to start this Activity directly so it does not return any value(after clicking a panel, the corresponding value is returned to the sender activity).

So, basically, I have to make difference between "calling for selection(result)" and "direct calling"(search).

I am not very happy with Null handling too but I don't have much of choice here. Maybe I can create a "DummyObject" and check if my came_from is equal to it. Another option is to write another selectorSub which is for direct calling only.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Thank you, you always start struggling and try to help.

In fact, everything worked due to the fact it was implemented with strings. Then, Erel advised me to use Object in order to get access to the "Me" keyword and thus not have to write the Activity name with each call.

However, in certain cases, I want to start this Activity directly so it does not return any value(after clicking a panel, the corresponding value is returned to the sender activity).

So, basically, I have to make difference between "calling for selection(result)" and "direct calling"(search).

I am not very happy with Null handling too but I don't have much of choice here. Maybe I can create a "DummyObject" and check if my came_from is equal to it. Another option is to write another selectorSub which is for direct calling only.
I think you should try the dummy object, since it will surely be reliable enough :)
 
Upvote 0

Penko

Active Member
Licensed User
Longtime User
I tricked it with using a single Boolean "direct" variable.

When I want to access it directly, a simply call a "directCalling" sub which prevents the execution of the pnl_Click even(I return 0 at the very beginning) which ensures the problematic code snippet is not accessed.

Thank you once more for participating in a thread of mine.
 
Upvote 0
Top