1

Help Me Please to find the error

Please when i click the button my application close

emp.XML

**XML file*

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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"
        android:background="@drawable/lawa"
        tools:context="com.example.johnwalls.projet.Main2Activity">

        <EditText
            android:id="@+id/username"
            android:layout_width="150dp"
            android:layout_height="30dp"
            android:ems="10"
            android:inputType="textPersonName"
            android:textSize="10dp"

            android:background="#ffffffff"
            android:textColor="#000"
            android:textColorHighlight="#ffffffff"
            android:phoneNumber="false"
            android:text=""
            style="@android:style/TextAppearance.Large"
            android:textStyle="bold"
            android:typeface="sans"

            android:layout_marginBottom="90dp"
            android:layout_alignBottom="@+id/pass"
            android:layout_alignLeft="@+id/pass"
            android:layout_alignStart="@+id/pass" />
        android:text="" />

        <EditText
            android:id="@+id/pass"
            android:layout_width="150dp"
            android:layout_height="30dp"
            android:ems="10"
            android:inputType="textPassword"
            android:textSize="10dp"

            android:background="#ffffffff"
            android:textColor="#000"
            android:textColorHighlight="#ffffffff"
            android:phoneNumber="false"
            android:text=""
            style="@android:style/TextAppearance.Large"
            android:textStyle="bold"
            android:typeface="sans"
            android:layout_marginLeft="11dp"

            android:layout_marginStart="11dp"
            android:layout_centerVertical="true"
            android:layout_alignLeft="@+id/log"
            android:layout_alignStart="@+id/log" />
        <Button
            android:text=""
            android:layout_width="105.0dp"
            android:layout_height="40.0dp"
            android:id="@+id/log"

            android:background="@drawable/log"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="340dp"
            android:textAllCaps="false"
            android:onClick=""
            />



        <Button
            android:text=""
            android:layout_width="105.0dp"
            android:layout_height="40.0dp"
            android:background="@drawable/ins"
            android:layout_marginLeft="120dp"
            android:layout_marginTop="340dp"
            android:textAllCaps="false"
            android:onClick="goButtonClicked"
            android:id="@+id/goButton"

            />



    </RelativeLayout>`

Main2Activity.java

    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;

    public class Main2Activity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.emp);
        }



        public void goButtonClicked(View v) {
            Intent i=new Intent(Main2Activity.this,SaveadminActivity.class);
            startActivity(i);
        }

    }

SaveadminActivity

    import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;



public class SaveadminActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.enregistreradmin);
    }
}


        [enter image description here][1]

What are you trying to achieve what are you expecting to get out What did you get out (include error messages) What else have you tried? What do you think is causing it? Why do you need to make a new question for it? Why is your problem different to other, similar questions on here?

14
  • Please fix your post including formatting and taking out the nonsense
    – codeMagic
    Mar 23, 2018 at 23:02
  • Please add your code from SaveadminActivity Mar 23, 2018 at 23:08
  • Okay and the Stacktrace would be useful too, you find it under logcat, just scroll to the bottom after the error occurs :) Mar 23, 2018 at 23:16
  • julien-100000 , sorry i don't understand you :(
    – john walls
    Mar 23, 2018 at 23:20
  • 2
    java.lang.IllegalStateException: Could not find method goButtonClicked(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'goButton'
    – john walls
    Mar 23, 2018 at 23:54

2 Answers 2

2

This is how you can solve the issue

emp.XML

  <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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"
        android:background="@drawable/lawa"
        tools:context="com.example.johnwalls.projet.Main2Activity">

        <EditText
            android:id="@+id/username"
            android:layout_width="150dp"
            android:layout_height="30dp"
            android:ems="10"
            android:inputType="textPersonName"
            android:textSize="10dp"

            android:background="#ffffffff"
            android:textColor="#000"
            android:textColorHighlight="#ffffffff"
            android:phoneNumber="false"
            android:text=""
            style="@android:style/TextAppearance.Large"
            android:textStyle="bold"
            android:typeface="sans"

            android:layout_marginBottom="90dp"
            android:layout_alignBottom="@+id/pass"
            android:layout_alignLeft="@+id/pass"
            android:layout_alignStart="@+id/pass" />
        android:text="" />

        <EditText
            android:id="@+id/pass"
            android:layout_width="150dp"
            android:layout_height="30dp"
            android:ems="10"
            android:inputType="textPassword"
            android:textSize="10dp"

            android:background="#ffffffff"
            android:textColor="#000"
            android:textColorHighlight="#ffffffff"
            android:phoneNumber="false"
            android:text=""
            style="@android:style/TextAppearance.Large"
            android:textStyle="bold"
            android:typeface="sans"
            android:layout_marginLeft="11dp"

            android:layout_marginStart="11dp"
            android:layout_centerVertical="true"
            android:layout_alignLeft="@+id/log"
            android:layout_alignStart="@+id/log" />
        <Button
            android:text=""
            android:layout_width="105.0dp"
            android:layout_height="40.0dp"
            android:id="@+id/log"

            android:background="@drawable/log"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="340dp"
            android:textAllCaps="false"
            />



        <Button
            android:text=""
            android:layout_width="105.0dp"
            android:layout_height="40.0dp"
            android:background="@drawable/ins"
            android:layout_marginLeft="120dp"
            android:layout_marginTop="340dp"
            android:textAllCaps="false"
            android:id="@+id/goButton"

            />



    </RelativeLayout>

Main2Activity.java

import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;

    public class Main2Activity extends AppCompatActivity {

       Button goButton;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.emp);
            goButton=(Button)findViewById(R.id.goButton);
            goButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                        Intent i=new Intent(Main2Activity.this,SaveadminActivity.class);
            startActivity(i); 
                }
            });
        }

    }
0

In Main2Activity delete goButton method and add to onCreate this

goButton=(Button)findViewById(R.id.goButton);
        goButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Intent i=new Intent(Main2Activity.this,SaveadminActivity.class);
        startActivity(i); 
            }
        });

Main2Activity will looks like this

    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;

    public class Main2Activity extends AppCompatActivity {

       Button goButton;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.emp);
            goButton=(Button)findViewById(R.id.goButton);
            goButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                        Intent i=new Intent(Main2Activity.this,SaveadminActivity.class);
            startActivity(i); 
                }
            });
}
2
  • This only will not solve the problem as he has to delete this line android:onClick="goButtonClicked" from the emp.XML Mar 24, 2018 at 11:23
  • 2
    true, didn't notice this
    – Mich
    Mar 24, 2018 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.