gpt4 book ai didi

android - 无法从 View 转换到复选框

转载 作者:搜寻专家 更新时间:2023-11-01 07:35:49 25 4
gpt4 key购买 nike

我一直在尝试在 eclipses workbench 中构建我的应用程序,但是我偶然发现了一条错误消息,内容为“无法从 View 转换到复选框”。我尝试了不同的方法来解决这个问题,但没有成功,想知道是否有人可以帮助我

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.widget.Checkbox;
import android.widget.TextView;

@SuppressLint("ParserError")
public class MainActivity extends Activity {
TextView textView;
CheckBox pepBox, cheeseBox;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pepBox =
(CheckBox) findViewById(R.id.checkBox1);
cheeseBox =
(CheckBox) findViewById(R.id.checkBox2);
textView =
(TextView) findViewById(R.id.textView2);
}

这是我用过的代码

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />

<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="57dp"
android:text="@string/pepperoni" />

<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/checkBox1"
android:layout_marginTop="33dp"
android:text="@string/extra_cheese" />

<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/checkBox1"
android:layout_below="@+id/textView1"
android:onClick="onButton1Click"
android:text="@string/show" />

这是我的xml文件谢谢

最佳答案

这让我挠了挠头。我必须将您的代码加载到 Eclipse 中才能找到它。将 import android.widget.Checkbox; 更改为 import android.widget.CheckBox;。 (注意复选框中的大写字母 B。)当我进行更改时,您发布的代码工作正常。

eclipse 没有突出显示有问题的导入吗?将鼠标光标悬停在突出显示上将为您提供一些修复方法的线索。 (如果我听起来有点居高临下,请原谅我。很难判断一个人是网站新手还是平台新手)

关于android - 无法从 View 转换到复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11480738/

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