gpt4 book ai didi

Android 在表格行中添加 TextView

转载 作者:行者123 更新时间:2023-11-30 04:18:05 25 4
gpt4 key购买 nike

好的,我已经声明了我的 main.xml 如下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal" >

<RelativeLayout
android:id="@+id/AdMob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" >
</RelativeLayout>

<ScrollView
android:id="@+id/scrollview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/AdMob" >

<TableLayout
android:id="@+id/tablelayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TableRow
android:id="@+id/tableRow0"
android:layout_height="wrap_content"
android:background="@drawable/banner" />

<TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/start_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="15sp" />

</TableRow>

<TableRow
android:id="@+id/tableRow2"
android:layout_height="wrap_content" >

<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Start Now" >
</Button>
</TableRow>
</TableLayout>
</ScrollView>

</RelativeLayout>

我的主要 Activity 是

package com.michaelpeerman.demotivational_posters;

import com.michaelpeerman.demotivational_posters.R;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView start_message = (TextView) findViewById(R.id.start_message);
start_message.setText(Html.fromHtml("Thank you for downloading \"Demotivational Posters\" \n Click start below to start. \n To advance to the next picture click the \"Next\" button. \n If you see an image you would like to download click the \"Download\" button. \n If you enjoy this app please leave a rating."));
}
}

当我去编译我的程序时,它强制自动关闭。 logcat 输出是

03-13 01:59:50.240: E/AndroidRuntime(14336): FATAL EXCEPTION: main
03-13 01:59:50.240: E/AndroidRuntime(14336): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.michaelpeerman.demotivational_posters/com.michaelpeerman.demotivational_posters.MainActivity}: java.lang.ClassCastException: android.widget.TableRow cannot be cast to android.widget.TextView
03-13 01:59:50.240: E/AndroidRuntime(14336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-13 01:59:50.240: E/AndroidRuntime(14336): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-13 01:59:50.240: E/AndroidRuntime(14336): at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-13 01:59:50.240: E/AndroidRuntime(14336): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-13 01:59:50.240: E/AndroidRuntime(14336): at android.os.Handler.dispatchMessage(Handler.java:99)
03-13 01:59:50.240: E/AndroidRuntime(14336): at android.os.Looper.loop(Looper.java:137)
03-13 01:59:50.240: E/AndroidRuntime(14336): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-13 01:59:50.240: E/AndroidRuntime(14336): at java.lang.reflect.Method.invokeNative(Native Method)
03-13 01:59:50.240: E/AndroidRuntime(14336): at java.lang.reflect.Method.invoke(Method.java:511)
03-13 01:59:50.240: E/AndroidRuntime(14336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-13 01:59:50.240: E/AndroidRuntime(14336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-13 01:59:50.240: E/AndroidRuntime(14336): at dalvik.system.NativeStart.main(Native Method)
03-13 01:59:50.240: E/AndroidRuntime(14336): Caused by: java.lang.ClassCastException: android.widget.TableRow cannot be cast to android.widget.TextView
03-13 01:59:50.240: E/AndroidRuntime(14336): at com.michaelpeerman.demotivational_posters.MainActivity.onCreate(MainActivity.java:16)
03-13 01:59:50.240: E/AndroidRuntime(14336): at android.app.Activity.performCreate(Activity.java:4465)
03-13 01:59:50.240: E/AndroidRuntime(14336): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-13 01:59:50.240: E/AndroidRuntime(14336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-13 01:59:50.240: E/AndroidRuntime(14336): ... 11 more

我不明白我将表格行转换为 TextView 是什么意思

最佳答案

您需要再次清理并重建您的项目。如果这不起作用,则关闭您的项目并再次打开刷新项目并运行。我试过你给的代码。它适用于我的情况。

关于Android 在表格行中添加 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9679110/

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