TableRow中的类强制转换异常

时间:2011-09-02 12:06:28

标签: android

我在处理TableRow时遇到了问题,请给我适当的解决方案

<我的Java文件中的

  tr1 = (TableRow)findViewById(R.id.facebook_raw);
  tr2 = (TableRow)findViewById(R.id.twitter_raw);

并在我的Xml文件中

<TableLayout android:layout_width="wrap_content"
            android:id="@+id/follow_us" android:layout_centerHorizontal="true"
            android:background="@drawable/listback" android:layout_height="wrap_content"
            android:stretchColumns="1" android:layout_marginRight="10dip"
            android:layout_marginLeft="10dip">
            <TableRow android:id="@+id/facebook_raw"
                android:layout_marginBottom="8dip">
                <ImageView android:layout_width="wrap_content"
                    android:src="@drawable/facebook" android:id="@+id/que1"
                    android:layout_height="wrap_content"></ImageView>
                <TextView android:text="Follow us on Facebook"
                    android:layout_width="wrap_content" android:textStyle="bold"
                    android:textColor="#000000" android:layout_marginLeft="15dip"
                    android:textSize="16sp" android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical" />
                <ImageView android:layout_width="wrap_content"
                    android:layout_marginRight="10dip" android:src="@drawable/arrow"
                    android:layout_gravity="center_vertical" android:layout_height="wrap_content"></ImageView>
            </TableRow>
            <View android:layout_height="1dip" android:background="#A9ABAD"
                android:layout_width="wrap_content" />
            <TableRow android:id="@+id/twitter_raw"
                android:layout_marginTop="8dip">
                <ImageView android:layout_width="wrap_content"
                    android:src="@drawable/twitter" android:layout_height="wrap_content"></ImageView>
                <TextView android:text="Follow us on Twitter"
                    android:layout_width="wrap_content" android:textStyle="bold"
                    android:textColor="#000000" android:layout_marginLeft="15dip"
                    android:textSize="16sp" android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical" />
                <ImageView android:layout_width="wrap_content"
                    android:layout_marginRight="10dip" android:src="@drawable/arrow"
                    android:layout_gravity="center_vertical" android:layout_height="wrap_content"></ImageView>
            </TableRow>
        </TableLayout>

错误...........

09-02 17:49:57.235: ERROR/AndroidRuntime(832): FATAL EXCEPTION: main
09-02 17:49:57.235: ERROR/AndroidRuntime(832): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stress/com.stress.TabGroup5Activity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stress/com.stress.More}: java.lang.ClassCastException: android.widget.ListView
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:1462)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.widget.TabHost.setCurrentTab(TabHost.java:326)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:132)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:456)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.view.View.performClick(View.java:2485)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.view.View$PerformClick.run(View.java:9080)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.os.Handler.handleCallback(Handler.java:587)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.os.Looper.loop(Looper.java:123)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.ActivityThread.main(ActivityThread.java:3647)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at java.lang.reflect.Method.invokeNative(Native Method)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at java.lang.reflect.Method.invoke(Method.java:507)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at dalvik.system.NativeStart.main(Native Method)
09-02 17:49:57.235: ERROR/AndroidRuntime(832): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stress/com.stress.More}: java.lang.ClassCastException: android.widget.ListView
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:1462)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at com.stress.TabGroupActivity.startChildActivity(TabGroupActivity.java:67)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at com.stress.TabGroup5Activity.onCreate(TabGroup5Activity.java:10)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     ... 18 more
09-02 17:49:57.235: ERROR/AndroidRuntime(832): Caused by: java.lang.ClassCastException: android.widget.ListView
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at com.stress.More.onCreate(More.java:44)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
09-02 17:49:57.235: ERROR/AndroidRuntime(832):     ... 25 more

1 个答案:

答案 0 :(得分:2)

尝试清理项目。在Eclipse中,这是从Java透视图的主菜单中的Project | Clean ....在命令行中,它是ant clean

由于您的布局中没有ListView,我的猜测是您的代码加载了错误的布局,可能是由于混乱的R值,清理将清除。