Android Question Weird Crash keeps happening

FrostCodes

Active Member
Licensed User
Hello everyone, my app has been getting this weird crash sometimes and I haven't been able to find the cause or when it happens, it happens randomly
does anyone know how to solve it? Also, the crash does not after immediately after the RewardedVideoAd_ReceiveAd and sleep.


B4X:
RewardedVideoAd_ReceiveAd
sending message to waiting queue (sleep)
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String
    at anywheresoftware.b4a.keywords.Common$12.run(Common.java:1215)
    at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1226)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8751)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String
    at anywheresoftware.b4a.keywords.Common.getComponentBA(Common.java:1252)
    at anywheresoftware.b4a.keywords.Common$12.run(Common.java:1158)
    ... 9 more
 

JohnC

Expert
Licensed User
Longtime User
The key is this line in the log:
B4X:
java.lang.Object cannot be cast to java.lang.String
Somewhere in your code an "object" is trying to be assigned to a String type variable.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
From poking around in Core.jar it looks like the error is arising during the processing of a CallSubDelayed call. The CallSubDelayed has posted a Runnable to the message queue and the error occurs when the message queue dispatches that Runnable. I can't say anymore than that as the Runnable code is wrapped in a Try-Catch block and the line 'Common.java:1215' is throwing the exception in the catch block.

It's only a guess, and maybe not a good one, but perhaps one of the arguments to the Sub being called is passed an Object when it should be a String.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Further examination shows the error occurs when the Component parameter of the CallSubdelayed is being cast to a String

1252: c = Class.forName(String.valueOf(BA.packageName) + "." + ((String)Component).toLowerCase(BA.cul));

This occurs when the Component is neither a Class instance nor a BAClass instance in which case it is assumed to be a String. Check your Component parameters.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Btw, I have done this before by forgetting to quote the method parameter of the CallSubdelayed. I don't think it throws an error in the IDE, just a warning about automatic string conversion. When you run the code though, boom...
 
Upvote 0
Top