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
272 views
in Technique[技术] by (71.8m points)

Unexplainable ClassCastException in android.widget.ProgressBar.onRestoreInstanceState

I've had my application out in the store for a while, but it seems it crashes occasionally according to the crash reports in the Developer Console, saying: java.lang.ClassCastException in android.widget.ProgressBar.onRestoreInstanceState with the stack trace:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.myapp/com.mycompany.myapp.activity.MyActivity}: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.ProgressBar$SavedState
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1996)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1174)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4503)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.ProgressBar$SavedState
at android.widget.ProgressBar.onRestoreInstanceState(ProgressBar.java:1093)
at android.view.View.dispatchRestoreInstanceState(View.java:9975)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2408)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2408)
at android.view.View.restoreHierarchyState(View.java:9951)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1611)
at android.app.Activity.onRestoreInstanceState(Activity.java:908)
at android.app.Activity.performRestoreInstanceState(Activity.java:880)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1102)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
... 11 more

The reason for these crashes eludes me, and I can't reproduce it on any of my devices. I don't have a onRestoreInstanceState overridden anywhere either. Can anyone point me in a direction that makes sense?

question from:https://stackoverflow.com/questions/15298184/unexplainable-classcastexception-in-android-widget-progressbar-onrestoreinstance

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

1 Reply

0 votes
by (71.8m points)

I've seen similar issues to this before, and it's because you have two id's that share the same name.

The onRestoreInstanceState has performed the findViewById method and the first view to be found was not the ProgressView.

Double check that your application does not reuse the same ID in two different places


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

...