我刚刚开始研究一个项目,我正在尝试施放EditTexts和一个按钮,我得到上面的错误,什么是奇怪的是一旦我擦除并重写它错误消失然后当我继续编码并再次检查错误回来了,我是个傻瓜。
public class Register extends AppCompatActivity{
AppCompatEditText et_name,et_user_name,et_user_pass;
AppCompatButton btn_register;
String name,userName,userPass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
et_name= (AppCompatEditText) findViewById(R.id.et_regname);
et_user_name= (AppCompatEditText) findViewById(R.id.et_regusername);
et_user_pass= (AppCompatEditText) findViewById(R.id.et_userpass);
btn_register= (AppCompatButton) findViewById(R.id.btn_register);
}
}
尝试清理项目现在似乎是一个更大的问题,构建失败 Register.xml
<?xml version="1.0" encoding="utf-8"?>
<!--suppress ALL -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#156a09">
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="@+id/et_regname"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="55dp"
android:hint="Name"
/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="@+id/et_regusername"
android:layout_below="@+id/et_regname"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:hint="Username"
/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="@+id/et_regpass"
android:hint="Password"
android:layout_below="@+id/et_regusername"
android:layout_alignStart="@+id/et_regusername"
android:layout_marginTop="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/btn_register"
android:layout_below="@+id/et_regpass"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:text="Registration Form"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
activitymain.xml:
<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#ca26c30b">
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="@+id/et_username"
android:hint="Username"
android:layout_margintop="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="116dp" />
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="@+id/et_userpass"
android:hint="password"
android:layout_marginTop="20dp"
android:layout_below="@+id/et_username"
android:layout_alignEnd="@+id/et_username"
android:inputType="textPassword"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/button"
android:layout_below="@+id/et_userpass"
android:layout_centerHorizontal="true"
android:layout_marginTop="59dp"
android:onClick="userLogin"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register Now"
android:id="@+id/button2"
android:layout_below="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:onClick="userRegister"
/>
</RelativeLayout>
Gradle Build:
Information:Gradle tasks [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]
:clean UP-TO-DATE
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library
:app:prepareComAndroidSupportSupportV42311Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
F:\MySqlDemo\app\src\main\res\layout\activity_main.xml
Error:(10) No resource identifier found for attribute 'layout_margintop' in package 'android'
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'F:\Software\Softies\Androidsdk\adt-bundle-windows-x86_64-20140702\sdk\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 6.02 secs
答案 0 :(得分:1)
希望此代码可以帮助您: -
public class Register extends Activity{
EditText et_name,et_user_name,et_user_pass;
Button btn_register;
String name,userName,userPass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_xml_file);
et_name= (EditText) findViewById(R.id.name);
et_user_name= (EditText) findViewById(R.id.username);
et_user_pass= (EditText) findViewById(R.id.password);
btn_register= (Button) findViewById(R.id.submitbutton);
}
}
您的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">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/name"
android:hint="Name"
android:layout_above="@+id/uername"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/username"
android:hint="Username"
android:layout_below="@+id/name"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/password"
android:inputType="textPassword"
android:hint="Password"
android:layout_below="@+id/username"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit "
android:id="@+id/submitbutton"
android:layout_below="@+id/password"
android:layout_centerHorizontal="true" />
</RelativeLayout>