开发者

class cast exception in TableRow

I found a problem in handling TableRow show please give me appropriate solution

in My Java File

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

and in my Xml file

<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">开发者_StackOverflow中文版;</ImageView>
            </TableRow>
        </TableLayout>

error...........

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


Try cleaning your project. In Eclipse, this is Project|Clean... from the Java perspective's main menu. At the command line, it is ant clean.

Since there is no ListView in your layout, my guess is that your code is loading the wrong layout, perhaps due to messed-up R values, which the cleaning will clear up.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜