-3

It shows the application has stopped but shows no error in the code, can someone explain why this is happening. Is there any pluglin to find error in such kind of codes Activity1

EditText  edt1,edt2,edt3;
Button btn1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        edt1=findViewById(R.id.edt1);
        edt2=findViewById(R.id.edt2);
        edt3=findViewById(R.id.edt3);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String str=edt2.getText().toString();
                String str2=edt3.getText().toString();
                Intent intent= new Intent(getApplicationContext(),Main2Activity.class);
                intent.putExtra("email",str);
                intent.putExtra("password",str2);
                startActivity(intent);

            }
        });
    }
}

Activity2


TextView edt21,edt22;
Button btn21;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        edt21=findViewById(R.id.edt21);
        edt22=findViewById(R.id.edt22);
        Intent intent=getIntent();
        String str= intent.getStringExtra("email");
        String str2= intent.getStringExtra("password");
        edt21.setText(str);
        edt22.setText(str2);



stdusic
  • 11
  • 4
  • For one, in `Activity1` you're calling a function of `btn1` but `btn1` has not been initialized previously so you're getting a `NullPointerException`. – pappbence96 Oct 31 '19 at 12:32
  • 2
    Possible duplicate of [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – a_local_nobody Oct 31 '19 at 12:32
  • this questions with less information.Not logcat is attached or pasted. – SIVAKUMAR.J Oct 31 '19 at 13:04

1 Answers1

0

You should intialize btn1. Activity doesn't know whether it is a button or view and where it is located. So, it is necessary to initialize it by findViewById() / use id from the activity_main.xml file directtly.