-1

Here is my code.

In the MainActivity.java, I called this method.

public void doViewRecord(View v){
    startActivity(new Intent(this, ActivityView.class));
}

And in the SecondActivity (ActivityView.java).

[This is where I get my error]

tv_id = findViewById(R.id.tvId);
    tv_name = findViewById(R.id.tvName);
    tv_course = findViewById(R.id.tvCourse);

    try{
        extra = getIntent().getExtras();
        id = extra.getString("id");
        tv_id.setText(id);
    }catch (Exception e){
        e.printStackTrace();
        displayError(e.getMessage());
    }

The error I get is this.

Error Message

I already tried the intent then bundle, but still it gives me an error.

sgxtract
  • 25
  • 5

1 Answers1

1

You have to put the string early on the intent

public void doViewRecord(View v){
    Intent intent = new Intent(this, ActivityView.class);
    intent.putExtra("id", "your-id");
    startActivity(intent);
}
Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167