android - ClassCastException occur when screen orientation change (AbsSpinner) -
my custom activity has 2 spinners. wait view create done , try rotate device app crashed. have tried methods searched here, cannot fix problem.
logcat
12-16 16:15:47.200: d/androidruntime(5332): shutting down vm 12-16 16:15:47.200: w/dalvikvm(5332): threadid=1: thread exiting uncaught exception (group=0x40154760) 12-16 16:15:47.260: e/androidruntime(5332): fatal exception: main 12-16 16:15:47.260: e/androidruntime(5332): java.lang.runtimeexception: unable start activity componentinfo{qt.r07/qt.r07.listview.fileselectactivity2}: java.lang.classcastexception: android.view.abssavedstate$1 cannot cast android.widget.absspinner$savedstate 12-16 16:15:47.260: e/androidruntime(5332): @ android.app.activitythread.performlaunchactivity(activitythread.java:1815) 12-16 16:15:47.260: e/androidruntime(5332): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1831) 12-16 16:15:47.260: e/androidruntime(5332): @ android.app.activitythread.handlerelaunchactivity(activitythread.java:3188) 12-16 16:15:47.260: e/androidruntime(5332): @ android.app.activitythread.access$600(activitythread.java:122) 12-16 16:15:47.260: e/androidruntime(5332): @ android.app.activitythread$h.handlemessage(activitythread.java:1028) 12-16 16:15:47.260: e/androidruntime(5332): @ android.os.handler.dispatchmessage(handler.java:99) 12-16 16:15:47.260: e/androidruntime(5332): @ android.os.looper.loop(looper.java:132) 12-16 16:15:47.260: e/androidruntime(5332): @ android.app.activitythread.main(activitythread.java:4123) 12-16 16:15:47.260: e/androidruntime(5332): @ java.lang.reflect.method.invokenative(native method) 12-16 16:15:47.260: e/androidruntime(5332): @ java.lang.reflect.method.invoke(method.java:491) 12-16 16:15:47.260: e/androidruntime(5332): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:841) 12-16 16:15:47.260: e/androidruntime(5332): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:599) 12-16 16:15:47.260: e/androidruntime(5332): @ dalvik.system.nativestart.main(native method) **12-16 16:15:47.260: e/androidruntime(5332): caused by: java.lang.classcastexception: android.view.abssavedstate$1 cannot cast android.widget.absspinner$savedstate** 12-16 16:15:47.260: e/androidruntime(5332): @ android.widget.absspinner.onrestoreinstancestate(absspinner.java:421) 12-16 16:15:47.260: e/androidruntime(5332): @ android.view.view.dispatchrestoreinstancestate(view.java:8316) 12-16 16:15:47.260: e/androidruntime(5332): @ android.view.viewgroup.dispatchthawselfonly(viewgroup.java:2038) 12-16 16:15:47.260: e/androidruntime(5332): @ android.widget.adapterview.dispatchrestoreinstancestate(adapterview.java:766) 12-16 16:15:47.260: e/androidruntime(5332): @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2024) 12-16 16:15:47.260: e/androidruntime(5332): @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2024) 12-16 16:15:47.260: e/androidruntime(5332): @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2024) 12-16 16:15:47.260: e/androidruntime(5332): @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2024) 12-16 16:15:47.260: e/androidruntime(5332): @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2024) 12-16 16:15:47.260: e/androidruntime(5332): @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2024) 12-16 16:15:47.260: e/androidruntime(5332): @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2024) 12-16 16:15:47.260: e/androidruntime(5332): @ android.view.view.restorehierarchystate(view.java:8295) 12-16 16:15:47.260: e/androidruntime(5332): @ com.android.internal.policy.impl.phonewindow.restorehierarchystate(phonewindow.java:1512) 12-16 16:15:47.260: e/androidruntime(5332): @ android.app.activity.onrestoreinstancestate(activity.java:898) 12-16 16:15:47.260: e/androidruntime(5332): @ android.app.activity.performrestoreinstancestate(activity.java:870) 12-16 16:15:47.260: e/androidruntime(5332): @ android.app.instrumentation.callactivityonrestoreinstancestate(instrumentation.java:1099) 12-16 16:15:47.260: e/androidruntime(5332): @ android.app.activitythread.performlaunchactivity(activitythread.java:1793) 12-16 16:15:47.260: e/androidruntime(5332): ... 12 more
layout
<?xml version="1.0" encoding="utf-8"?> <!-- tiger 20141211 --> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/framelayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/file_manager_frame" > <linearlayout android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="50dp" android:background="@drawable/file_manager_linear" android:orientation="horizontal" > <framelayout android:id="@+id/framelayout2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginbottom="20dp" android:layout_marginleft="20dp" android:layout_marginright="10dp" android:layout_margintop="20dp" android:layout_weight="1" > <linearlayout android:id="@+id/linearlayout2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" > <linearlayout android:id="@+id/linearlayout3" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" > <framelayout android:id="@+id/framelayout3" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" > <textview android:id="@+id/text_view_office" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|center_horizontal" android:gravity="center" android:text="地政事務所" android:textcolor="@color/white" android:textsize="32sp" /> </framelayout> <framelayout android:id="@+id/framelayout4" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" > <textview android:id="@+id/text_view_section" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:text="地段" android:textcolor="@color/white" android:textsize="32sp" /> </framelayout> <framelayout android:id="@+id/framelayout5" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" > <textview android:id="@+id/text_view_land_no" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|center_horizontal" android:gravity="center" android:text="地號" android:textcolor="@color/white" android:textsize="32sp" /> </framelayout> </linearlayout> <linearlayout android:id="@+id/linearlayout4" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical" > <framelayout android:id="@+id/framelayout6" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" > <spinner android:id="@+id/spinner_office" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom|center_horizontal" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:background="#ffc8e6c9" /> </framelayout> <framelayout android:id="@+id/framelayout7" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" > <spinner android:id="@+id/spinner_section" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:background="#ffc8e6c9" /> </framelayout> <framelayout android:id="@+id/framelayout8" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" > <linearlayout android:id="@+id/linearlayout5" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > <edittext android:id="@+id/edit_text_land_no" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top|center_horizontal" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_weight="1" android:ems="10" android:gravity="center" android:imeoptions="flagnofullscreen" android:inputtype="number|text" android:maxlength="9" android:textcolor="@color/black" android:textsize="32sp" > <requestfocus /> </edittext> <button android:id="@+id/button_land_no_add" android:layout_width="50dp" android:layout_height="50dp" android:layout_gravity="top|center_horizontal" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:background="@drawable/file_manager_button_oval" android:text="+" android:textcolor="#ffc8e6c9" android:textsize="32sp" /> </linearlayout> </framelayout> </linearlayout> </linearlayout> </framelayout> <linearlayout android:id="@+id/linearlayout6" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginbottom="20dp" android:layout_marginleft="10dp" android:layout_marginright="20dp" android:layout_margintop="20dp" android:layout_weight="1" android:orientation="vertical" > <textview android:id="@+id/textview1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="5dp" android:gravity="center" android:text="地號列表" android:textcolor="@color/white" android:textsize="32sp" /> <framelayout android:id="@+id/framelayout9" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:layout_weight="1" > <listview android:id="@+id/list_view_land_no" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#ffc8e6c9" > </listview> </framelayout> <button android:id="@+id/button_file_manager_ok" android:layout_width="100dp" android:layout_height="50dp" android:layout_gravity="center_horizontal" android:layout_margin="5dp" android:background="@drawable/file_manager_button_rectangle" android:text="確定" android:textcolor="#ffc8e6c9" android:textsize="32sp" /> </linearlayout> </linearlayout> </framelayout>
code
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.setcontentview(r.layout.filemanager_r07); ... adapter_office = new arrayadapter<string>(this, r.drawable.file_manager_spinner, office_list); spinner_office = (spinner)findviewbyid(r.id.spinner_office); adapter_office.setdropdownviewresource(r.drawable.file_manager_spinner_dropdown); spinner_office.setadapter(adapter_office); spinner_office.setid(0); spinner_office.setonitemselectedlistener(this); adapter_section = new arrayadapter<string>(this, r.drawable.file_manager_spinner); showmapfilelist(map_path + "/aa"); // adapter_section content add in method spinner_section = (spinner)findviewbyid(r.id.spinner_section); adapter_section.setdropdownviewresource(r.drawable.file_manager_spinner_dropdown); spinner_section.setadapter(adapter_section); spinner_section.setid(1); spinner_section.setonitemselectedlistener(this); edit_text_land_no = (edittext)findviewbyid(r.id.edit_text_land_no); button_land_no_add = (button)findviewbyid(r.id.button_land_no_add); button_land_no_add.setid(1); button_land_no_add.setonclicklistener(this); list_view_land_no = (listview)findviewbyid(r.id.list_view_land_no); button_file_manager_ok = (button)findviewbyid(r.id.button_file_manager_ok); button_file_manager_ok.setid(10); button_file_manager_ok.setonclicklistener(this); }
Comments
Post a Comment