遇到了一个难缠的问题,搜了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 = com.autonavi.connector.clientsdk.Sender@432462d8 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.(Socket.java:178) 07-02 15:40:31.885: W/System.err(6711): at java.net.Socket. (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. (Socket.java:178) 07-02 15:40:41.945: W/System.err(6711): at java.net.Socket. (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",应该不是网友说的这种情况,但是我也不知道为什么传的AbsSavedState$1给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的滚动条位置,这个对我影响也不是很大,规避这个问题我能想到有如下两种:
将AndroidMainifest.xml中android:targetSdkVersion降为18以下(如果需要记录这个状态,可以在onSaveInstanceState中记录位置,onRestoreInstanceState中恢复就可以了);
不让View保存状态:
android:saveEnabled="false"|setSaveEnabled(false)|不要给view设置id
/** * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for * this view and its children. May be overridden to modify how freezing happens to a * view's children; for example, some views may want to not store state for their children. * * @param container The SparseArray in which to save the view's state. * * @see #dispatchRestoreInstanceState(android.util.SparseArray) * @see #saveHierarchyState(android.util.SparseArray) * @see #onSaveInstanceState() */ protected void dispatchSaveInstanceState(SparseArraycontainer) { if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED; Parcelable state = onSaveInstanceState(); if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) { throw new IllegalStateException( "Derived class did not call super.onSaveInstanceState()"); } if (state != null) { // Log.i("View", "Freezing #" + Integer.toHexString(mID) // + ": " + state); container.put(mID, state); } } }