所以我想学习Android Studio,这是我第一次做任何事情。我正在尝试制作一个简单的登录应用程序,并且我只添加了两个EditText
字段,但它们未被识别。Android Studio无法识别输入字段“字段从不使用”
我得到这个错误;
Cannot resolve symbol EditText
虽然我确信我有我的应用程序的EditText
场。
这是Java代码:
package localhost.testloginphpapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
EditText usernameField, passwordField;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
和XML代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="localhost.testloginphpapp.MainActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<EditText
android:id="@+id/usernameField"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Username"
tools:layout_editor_absoluteX="85dp"
tools:layout_editor_absoluteY="133dp" />
<EditText
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
tools:layout_editor_absoluteX="85dp"
tools:layout_editor_absoluteY="190dp" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
tools:layout_editor_absoluteX="148dp"
tools:layout_editor_absoluteY="245dp" />
</android.support.constraint.ConstraintLayout>
非常感谢。
这是你完整的代码?因为在访问它们之前,如果你没有初始化它们,通常会抛出这个错误代码? – BAAAZINGA
@BAAAZINGA是的,这就是所有事情,如果我可以问什么呢? – user6613235
它应该说“他们”,结果成为“他们”:') – BAAAZINGA