1

I'm trying to display the name inputted by the user on a basic form I created using Explicit intent on a second activity on a TextView but when I click the button the app crashes with the following "Unfortunately, formIntent has stopped" but my code has no errors. I got this to work with a Toast message on new activity but with a TextView. Any help would be appreciated.

Here's my First Activity `public class MainActivity extends AppCompatActivity {

Button submit;
TextView name;


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

        submit = (Button)findViewById(R.id.btnSubmit);
        name = (TextView)findViewById(R.id.editTextname);



    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //from sending Activity
            String userName = name.getText().toString();
            String value = "Thank you " + userName + "your request is being processed" ;
            Intent sendIntent = new Intent(v.getContext(), Main2Activity.class);
            sendIntent.putExtra("userName", value);
            //Verify that the intent will resolve to an activity
            if (sendIntent.resolveActivity(getPackageManager()) != null)
            {
                startActivity(sendIntent);
            }
        }


    });
}

} ` Here's My second Activity

public class Main2Activity extends AppCompatActivity {

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

    Bundle data = getIntent().getExtras();
    if(data == null){
        return;
    }
    String getName = getIntent().getExtras().getString("userName");
    final TextView inputMessage = (TextView)findViewById(R.id.display);
    inputMessage.setText(getName);
}

}

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
S.Byrne
  • 75
  • 1
  • 8

1 Answers1

2

Please change this line to your activity name

Intent sendIntent = new Intent(MainActivity.this, Main2Activity.class);
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31