0

i just started working on a project,i am trying to cast EditTexts and a button and i get above error,whats weird is once i erase and rewrite it error goes away then when i continue to code and it checks again the error comes back,am a begginer

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);


    }
}

Tried to clean project now seems a bigger problem,the build fails 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
Hilary Mwape
  • 425
  • 1
  • 4
  • 15

1 Answers1

1

Hope this code help you :-

 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);


        }
    }

your XML file Code:-

<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>
InsaneCat
  • 2,115
  • 5
  • 21
  • 40
  • it helps,But my problem remains – Hilary Mwape Dec 17 '15 at 11:36
  • Please add your XML file code here. and which error comes? – InsaneCat Dec 17 '15 at 11:43
  • after super.onCreate(savedInstanceState); write setContentView(R.layout.activity_main); and clean project. still you can got this error? – InsaneCat Dec 17 '15 at 12:01
  • yes i did that after was correctd to,and now the build fails error above – Hilary Mwape Dec 17 '15 at 12:02
  • hope this helps you. 1> http://stackoverflow.com/questions/29045129/android-java-exe-finished-with-non-zero-exit-value-1 2> http://stackoverflow.com/questions/29965398/gradle-finished-with-non-zero-exit-value-1-ic-launcher-png-error-duplicate-fi – InsaneCat Dec 17 '15 at 12:11
  • ok so managed to get ridof the build errors,had to do with wrong code in xml,so back to square one with unexpected cast thing – Hilary Mwape Dec 17 '15 at 14:41
  • I previously wasnt able to extend Activity,but after downloading new android Studio i was able to follow your code,everything works fine now thanks http://stackoverflow.com/users/3974530/pranav-bhatt – Hilary Mwape Dec 17 '15 at 14:56
  • Cool.. enjoy :) Please up vote if this is useful for you. – InsaneCat Dec 18 '15 at 05:30