View onRestoreInstanceState ClassCastException

遇到了一个难缠的问题,搜了N天的没有解决:

07-02 15:40:25.415: D/LocateService(6711): onLocationChanged: AMapLocation location =Location[lbs 0.000000,0.000000 acc=0 t=?!? et=?!? {Bundle[{adcode=, citycode=, desc=}]}]
07-02 15:40:25.425: D/AMapLocateListener(6711): onLocationChanged: location = Location[lbs 0.000000,0.000000 acc=0 t=?!? et=?!? {Bundle[{adcode=, citycode=, desc=}]}]
07-02 15:40:25.475: I/AuthFailure(6711): INVALID_USER_SCODE
07-02 15:40:29.105: D/GatewayPresentor(6711): logout: component = push
07-02 15:40:29.105: D/GatewayComponent(6711): logout
07-02 15:40:29.105: W/GatewayComponent(6711): mLogged = false, mSender = [email protected]
07-02 15:40:29.105: D/WorkOrderFragment(6711): onDetach
07-02 15:40:29.105: D/OrderFragment(6711): onDetach
07-02 15:40:29.115: D/GatewayPresentor(6711): login: component = push, accessKey = 2, userId = 2, token = 5ad04ba7-de02-4203-a077-a79581c89252
07-02 15:40:29.115: D/GatewayComponent(6711): login: accessKey = 2, userId = 2, token = 5ad04ba7-de02-4203-a077-a79581c89252
07-02 15:40:29.115: I/Sender(6711): 生成消息号:6166812093405200387
07-02 15:40:29.125: D/ReadableDatabaseHelper(6711): query: distinct = false, table = TWorkOrder, columns = null, selection = create_time >= datetime(‘2015-07-02 15:38:29‘), selectionArgs = null, groupBy = null, having = null, orderBy = null, limit =null
07-02 15:40:29.125: D/OrderFragment(6711): onAttach
07-02 15:40:29.155: D/AndroidRuntime(6711): Shutting down VM
07-02 15:40:29.155: W/dalvikvm(6711): threadid=1: thread exiting with uncaught exception (group=0x4173cd58)
07-02 15:40:29.155: E/AndroidRuntime(6711): FATAL EXCEPTION: main
07-02 15:40:29.155: E/AndroidRuntime(6711): Process: com.autonavi.taoparking.parker, PID: 6711
07-02 15:40:29.155: E/AndroidRuntime(6711): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.autonavi.taoparking.parker/com.autonavi.taoparking.parker.ManageOrderActivity}: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.HorizontalScrollView$SavedState
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2190)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2239)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3730)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.app.ActivityThread.access$900(ActivityThread.java:141)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.os.Handler.dispatchMessage(Handler.java:102)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.os.Looper.loop(Looper.java:136)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.app.ActivityThread.main(ActivityThread.java:5047)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at java.lang.reflect.Method.invokeNative(Native Method)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at java.lang.reflect.Method.invoke(Method.java:515)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at dalvik.system.NativeStart.main(Native Method)
07-02 15:40:29.155: E/AndroidRuntime(6711): Caused by: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.HorizontalScrollView$SavedState
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.widget.HorizontalScrollView.onRestoreInstanceState(HorizontalScrollView.java:1659)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.view.View.dispatchRestoreInstanceState(View.java:12810)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2637)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2643)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2643)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.view.View.restoreHierarchyState(View.java:12788)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1744)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.app.Activity.onRestoreInstanceState(Activity.java:955)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.app.Activity.performRestoreInstanceState(Activity.java:927)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1138)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
07-02 15:40:29.155: E/AndroidRuntime(6711): 	... 12 more
07-02 15:40:31.695: I/Sender(6711): ..............发送心跳
07-02 15:40:31.825: I/Sender(6711): 重试连接到服务器
07-02 15:40:31.885: W/System.err(6711): java.net.ConnectException: failed to connect to /120.26.196.74 (port 10000): connect failed: ECONNREFUSED (Connection refused)
07-02 15:40:31.885: W/System.err(6711): 	at libcore.io.IoBridge.connect(IoBridge.java:114)
07-02 15:40:31.885: W/System.err(6711): 	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
07-02 15:40:31.885: W/System.err(6711): 	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
07-02 15:40:31.885: W/System.err(6711): 	at java.net.Socket.startupSocket(Socket.java:566)
07-02 15:40:31.885: W/System.err(6711): 	at java.net.Socket.tryAllAddresses(Socket.java:128)
07-02 15:40:31.885: W/System.err(6711): 	at java.net.Socket.<init>(Socket.java:178)
07-02 15:40:31.885: W/System.err(6711): 	at java.net.Socket.<init>(Socket.java:150)
07-02 15:40:31.885: W/System.err(6711): 	at com.autonavi.connector.clientsdk.ClientContext$1.run(ClientContext.java:74)
07-02 15:40:31.885: W/System.err(6711): 	at java.lang.Thread.run(Thread.java:841)
07-02 15:40:31.885: W/System.err(6711): Caused by: libcore.io.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
07-02 15:40:31.885: W/System.err(6711): 	at libcore.io.Posix.connect(Native Method)
07-02 15:40:31.885: W/System.err(6711): 	at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
07-02 15:40:31.885: W/System.err(6711): 	at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
07-02 15:40:31.885: W/System.err(6711): 	at libcore.io.IoBridge.connect(IoBridge.java:112)
07-02 15:40:31.885: W/System.err(6711): 	... 8 more
07-02 15:40:31.885: W/Sender(6711): failed to connect to /120.26.196.74 (port 10000): connect failed: ECONNREFUSED (Connection refused)
07-02 15:40:41.695: I/Sender(6711): ..............发送心跳
07-02 15:40:41.885: I/Sender(6711): 重试连接到服务器
07-02 15:40:41.945: W/GatewayComponent(6711): mLogAction = LOGIN, failure: code = -2004, message = 发送消息没有回执确认
07-02 15:40:41.945: D/GatewayService(6711): mLocationLog.onFailed: code = -2004, message = 发送消息没有回执确认
07-02 15:40:41.945: W/System.err(6711): java.net.ConnectException: failed to connect to /120.26.196.74 (port 10000): connect failed: ECONNREFUSED (Connection refused)
07-02 15:40:41.945: W/System.err(6711): 	at libcore.io.IoBridge.connect(IoBridge.java:114)
07-02 15:40:41.945: W/System.err(6711): 	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
07-02 15:40:41.945: W/System.err(6711): 	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
07-02 15:40:41.945: W/System.err(6711): 	at java.net.Socket.startupSocket(Socket.java:566)
07-02 15:40:41.945: W/System.err(6711): 	at java.net.Socket.tryAllAddresses(Socket.java:128)
07-02 15:40:41.945: W/System.err(6711): 	at java.net.Socket.<init>(Socket.java:178)
07-02 15:40:41.945: W/System.err(6711): 	at java.net.Socket.<init>(Socket.java:150)
07-02 15:40:41.945: W/System.err(6711): 	at com.autonavi.connector.clientsdk.ClientContext$1.run(ClientContext.java:74)
07-02 15:40:41.945: W/System.err(6711): 	at java.lang.Thread.run(Thread.java:841)
07-02 15:40:41.945: W/System.err(6711): Caused by: libcore.io.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
07-02 15:40:41.945: W/System.err(6711): 	at libcore.io.Posix.connect(Native Method)
07-02 15:40:41.945: W/System.err(6711): 	at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
07-02 15:40:41.945: W/System.err(6711): 	at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
07-02 15:40:41.945: W/System.err(6711): 	at libcore.io.IoBridge.connect(IoBridge.java:112)
07-02 15:40:41.945: W/System.err(6711): 	... 8 more
07-02 15:40:41.945: W/Sender(6711): failed to connect to /120.26.196.74 (port 10000): connect failed: ECONNREFUSED (Connection refused)
07-02 15:40:43.935: W/GatewayComponent(6711): mLogAction = LOGIN, failure: code = -2004, message = 发送消息没有回执确认
07-02 15:40:43.935: D/GatewayService(6711): mPushLog.onFailed: code = -2004, message = 发送消息没有回执确认

网上大部分人都说是因为同一个页面(Activity),不同的View使用了相同的ID,导致在恢复时,findViewById,强制转换SaveState类型错误,可是我对比了半天整个工程中就一个SlidingTabLayout(继承HorizontalScrollView)使用了android:id="@+id/slidingTabLayout",应该不是网友说的饿这种情况,无奈去翻HorizontalScrollView的源码:

    @Override
    protected void onRestoreInstanceState(Parcelable state) {
        if (mContext.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            // Some old apps reused IDs in ways they shouldn‘t have.
            // Don‘t break them, but they don‘t get scroll state restoration.
            super.onRestoreInstanceState(state);
            return;
        }
        SavedState ss = (SavedState) state;
        super.onRestoreInstanceState(ss.getSuperState());
        mSavedState = ss;
        requestLayout();
    }

大概意思就是在Android API 18(4.2.2和4.4.2之间的一个版本)以前,不会保存ScrollView的滚动条位置,这个对我影响也不是很大,规避这个问题我能想到有如下两种:

  1. 将AndroidMainifest.xml中android:targetSdkVersion降为18以下(如果需要记录这个状态,可以在onSaveInstanceState中记录位置,onRestoreInstanceState中恢复就可以了);
  2. try catch处理,虽然根本上没有解决,但是避免了程序crash;
	@Override
	protected void onRestoreInstanceState(Parcelable state) {
		LogUtil.d(LOG_TAG, "onRestoreInstanceState: state = " + state);
		try {
			super.onRestoreInstanceState(state);
		} catch (ClassCastException e) {
			e.printStackTrace();
		}
	}
时间: 2024-10-22 04:32:15

View onRestoreInstanceState ClassCastException的相关文章

【案例分享】仿QQ5.0侧滑菜单ResideMenu

本文由孙国威 原创.如需转载,请注明出处! 为了后续对这个项目进行优化,比如透明度动画.背景图的位移动画,以及性能上的优化. 我把这个项目上传到github上面,请大家随时关注. github地址https://github.com/sunguowei 最近项目要做一个QQ5.0的侧滑菜单效果,和传统的侧滑菜单存在着一些差异.想必大家都已经见识过了. 为了不重复发明轮子,先去github上面搜索了一番. 发现了几个类似的,但是还是有一些不同. 下面是搜索到的类似的开源项目. RESideMenu

【转】仿QQ5.0侧滑菜单ResideMenu

本文由孙国威 原创.如需转载,请注明出处! 原文:http://blog.csdn.net/manoel/article/details/39013095 为了后续对这个项目进行优化,比如透明度动画.背景图的位移动画,以及性能上的优化. 我把这个项目上传到github上面,请大家随时关注. github地址https://github.com/sunguowei 最近项目要做一个QQ5.0的侧滑菜单效果,和传统的侧滑菜单存在着一些差异.想必大家都已经见识过了. 为了不重复发明轮子,先去githu

【案例分享】仿QQ5.0側滑菜单ResideMenu

本文由孙国威 原创.如需转载,请注明出处! 为了兴许对这个项目进行优化,比方透明度动画.背景图的位移动画.以及性能上的优化. 我把这个项目上传到github上面,请大家随时关注. github地址https://github.com/sunguowei 近期项目要做一个QQ5.0的側滑菜单效果.和传统的側滑菜单存在着一些差异. 想必大家都已经见识过了. 为了不反复发明轮子,先去github上面搜索了一番. 发现了几个相似的,可是还是有一些不同. 以下是搜索到的相似的开源项目. RESideMen

Android开发之手把手教你写ButterKnife框架(三)

欢迎转载,转载请标明出处: http://blog.csdn.net/johnny901114/article/details/52672188 本文出自:[余志强的博客] 一.概述 上一篇博客讲了,如何在android studio使用apt < Android开发之手把手教你写ButterKnife框架(二)> 然后在Processor里生成自己的代码,把要输出的类,通过StringBuilder拼接字符串,然后输出. try { // write the file JavaFileObj

学习Butterknife的一点心得(系列)三

一 运行期 我们在activity中的onCreate方法中会调用ButterKnife.bind(this);我们进入这个方法: public static void bind(Activity target) { bind(target, target, Finder.ACTIVITY); } target是这个activity,再进入bind方法, static void bind(Object target, Object source, Finder finder) { Class<?

好吧就让我们结束这一切吧

http://www.tudou.com/programs/view/K7lbU7LsiJI/HGN13.htmlhttp://www.tudou.com/programs/view/SfcF7r7DsCk/XCWU7.htmlhttp://www.tudou.com/programs/view/BbljqbN52ZY/ieGvM.htmlhttp://www.tudou.com/programs/view/R4thdEitDik/17gGr.htmlhttp://www.tudou.com/p

法涉法而尴尬的收入法国

http://www.tudou.com/programs/view/pQOO07vn4Sc/l99Fi.htmlhttp://www.tudou.com/programs/view/EDJkM6ojYkc/r7RA6.htmlhttp://www.tudou.com/programs/view/Gf0zVZygPtU/EmvXY.htmlhttp://www.tudou.com/programs/view/UhqFbgbyQ6k/Z23Lx.htmlhttp://www.tudou.com/p

我不要说谎好吗

http://www.tudou.com/programs/view/KhjSmQKHEzM/McEy9.htmlhttp://www.tudou.com/programs/view/5FNDTTRKi6Y/9719g.htmlhttp://www.tudou.com/programs/view/UWFf0dz2DEk/3xPj2.htmlhttp://www.tudou.com/programs/view/b2zsYr4dCZg/gv6FP.htmlhttp://www.tudou.com/p

我不要说谎

http://www.tudou.com/programs/view/KhjSmQKHEzM/McEy9.htmlhttp://www.tudou.com/programs/view/5FNDTTRKi6Y/9719g.htmlhttp://www.tudou.com/programs/view/UWFf0dz2DEk/3xPj2.htmlhttp://www.tudou.com/programs/view/b2zsYr4dCZg/gv6FP.htmlhttp://www.tudou.com/p