gpt4 book ai didi

java - 安卓SDK : findViewById(int) undefined for type

转载 作者:行者123 更新时间:2023-11-29 21:47:44 25 4
gpt4 key购买 nike

这是我第一次尝试创建 Android 应用程序,所以我犯了很多烦人的初学者错误!现在我只是想创建一个非常简单的登录/注册系统。但是,我似乎误解了如何处理用户输入的输入。从我在这里看到的上一篇文章中,我正在尝试做这样的事情:

//in Register class
public void submission(View view){
//Call User Constructor based on info received from Registration Activity
EditText enteredUser = (EditText)findViewbyId(R.id.enteredUser);
//then use the input from this field to do other stuff

}

但是由于某些原因,我不断收到错误消息,即 findViewById(int) 未定义类型 Register(我当前所在的类的名称)。有人能告诉我我做错了什么吗?我很确定我在顶部 (android.widget.EditText) 有正确的导入语句。

对应的xml代码如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Register" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter New UserName:" />

<EditText
android:id="@+id/enteredUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:ems="10" >

<requestFocus />
</EditText>

...more input buttons etc...

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/confirmPass"
android:layout_alignParentBottom="true"
android:layout_marginBottom="64dp"
android:onClick = "submission" <----- Used to call the submission function after
android:text="Submit" /> all inputs have been filled

</RelativeLayout>

很抱歉问了一个冗长的问题,但我将不胜感激任何帮助。

谢谢!

最佳答案

你的编译时错误是因为打字错误:

findViewbyId

需要

findViewById

然后确保在调用 super.onCreate(savedInstanceState) 之后调用 setContentView()。我强烈建议您关注 Building Your First App教程,并清楚地关注代码。

和往常一样,familiarize yourself with the documentation .如果您有编译时错误,请先检查它,您可能只是输入错误!

关于java - 安卓SDK : findViewById(int) undefined for type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15329406/

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