gpt4 book ai didi

android - TableRow 中的类转换异常

转载 作者:行者123 更新时间:2023-11-29 22:20:46 28 4
gpt4 key购买 nike

我在处理 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

最佳答案

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

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

关于android - TableRow 中的类转换异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7283160/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com