gpt4 book ai didi

java - 意外转换为 appcompatedittext

转载 作者:行者123 更新时间:2023-12-01 10:43:17 26 4
gpt4 key购买 nike

我刚刚开始处理一个项目,我正在尝试转换 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);


}
}

尝试清理项目现在似乎是一个更大的问题,构建失败注册.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 构建:

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

最佳答案

希望这段代码对您有所帮助:-

 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>

关于java - 意外转换为 appcompatedittext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34333328/

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