我的自定义Activity有两个微调器。 我等待视图创建完成并尝试旋转设备但我的应用程序崩溃了。 我已经尝试了一些我在这里搜索过的方法,但无法解决这个问题。
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 with 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 to start activity ComponentInfo{qt.r07/qt.r07.listview.FileSelectActivity2}: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.AbsSpinner$SavedState
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3188)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1028)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.os.Handler.dispatchMessage(Handler.java:99)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.os.Looper.loop(Looper.java:132)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.app.ActivityThread.main(ActivityThread.java:4123)
12-16 16:15:47.260: E/AndroidRuntime(5332): at java.lang.reflect.Method.invokeNative(Native Method)
12-16 16:15:47.260: E/AndroidRuntime(5332): at java.lang.reflect.Method.invoke(Method.java:491)
12-16 16:15:47.260: E/AndroidRuntime(5332): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
12-16 16:15:47.260: E/AndroidRuntime(5332): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
12-16 16:15:47.260: E/AndroidRuntime(5332): at 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 be cast to android.widget.AbsSpinner$SavedState**
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.widget.AbsSpinner.onRestoreInstanceState(AbsSpinner.java:421)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.view.View.dispatchRestoreInstanceState(View.java:8316)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:2038)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.widget.AdapterView.dispatchRestoreInstanceState(AdapterView.java:766)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2024)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.view.View.restoreHierarchyState(View.java:8295)
12-16 16:15:47.260: E/AndroidRuntime(5332): at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1512)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.app.Activity.onRestoreInstanceState(Activity.java:898)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.app.Activity.performRestoreInstanceState(Activity.java:870)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1099)
12-16 16:15:47.260: E/AndroidRuntime(5332): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1793)
12-16 16:15:47.260: E/AndroidRuntime(5332): ... 12 more
布局
<?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>
代码
@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 this 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);
}