I'm having a strange problem with ClassCastException on Android. One class cannot be casted to the same class:
java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.ClassCastException: com.example.model.BadeWrapper cannot be cast to com.example.model.BadgeWrapper
java.lang.ClassCastException: com.example.events.widgets.TouchyWebView cannot be cast to com.example.events.widgets.TouchyWebView
java.lang.ClassCastException: com.example.friends.widgets.FriendsTabView cannot be cast to com.example.friends.widgets.FriendsTabView
When I find the line with error, all it does is finding view by id or creating fragment with arguments e.g.:
FriendsTabView friendsTabView;
friendsTabView = (FriendsTabView) view.findViewById(R.id.friends_bottom_tab_panel);
As my BugSense tells, this problem occurs only on Samsung Galaxy S5 with android 5.0.0 (samsung SM-G900F). I have never met this problem on my other devices:
Anyone met this problem before? Is there any way to fix it?
Introduction. ClassCastException is a runtime exception raised in Java when we try to improperly cast a class from one type to another. It's thrown to indicate that the code has attempted to cast an object to a related class, but of which it is not an instance.
// type cast an parent type to its child type. In order to deal with ClassCastException be careful that when you're trying to typecast an object of a class into another class ensure that the new type belongs to one of its parent classes or do not try to typecast a parent object to its child type.
You would get a ClassCastException, but not whithin the cast-method, but at the assignment to s. But this will still lead to an error later, when the you use your class.
ClassCastException is one of the unchecked exception in Java. It can occur in our program when we tried to convert an object of one class type into an object of another class type.
Ok I where the problem is. Looks like Samsung on Android 5.0 probably still uses old implementation of multidex (used in Android L Preview), so if your app exceeds the 64k limit, it will crash in random places on your app where you use (ExampleClass) object
cast.
More info on this problem can be found here and here.
We're also seeing this crash happen thousands of times per day. Crashlytics reports the crash as 100% Samsung devices (99% "SM G900F[Q]" device), and 100% Android 5.x. Seems to be another multidex issue on Samsung + Lollipop devices, as a.jaskev reports in #3.
Looks like we have to wait until Samsung resolve this problem. Right now all we can do is watching our spam on mailbox with bug reports :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With