Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
423 views
in Technique[技术] by (71.8m points)

classcastexception - Class cast exception to same class on Android

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:

  • Motorola Moto G 1st gen (Android 5.0.1)
  • Samsung Galaxy S3 Mini (Android 4.1.2)
  • LG G2 Mini (Android 4.4.2)
  • Sony Xperia L (Android 4.1.2)

Anyone met this problem before? Is there any way to fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...