0

NullPointerException error is occurring in this line of code in

Receiver code:

String summaryResult = ReceiverBundle.getString("summaryResult");

For what reason?

Sender Code:

    @Override
        public void onClick(View view) {
                
       Intent senderIntent = new Intent(getApplicationContext(), UserRegistration1.class);
       Bundle senderBundle = new Bundle();
       senderBundle.putString("summaryResult", summaryResult);

       senderIntent.putExtras(senderBundle);
       startActivity(senderIntent);

       Toast.makeText(getApplicationContext(), "It was sent: " + summaryResult, Toast.LENGTH_LONG).show();
       Intent intent = new Intent(getApplicationContext(), UserRegistration1.class);
       startActivity(intent);
            
}});

Receiver Code:

@Override
    protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);
        setContentView(R.layout.UserRegistration1);
        Intent ReceiverIntent = getIntent();
        Bundle ReceiverBundle = ReceiverIntent.getExtras();
        String summaryResult = ReceiverBundle.getString("summaryResult"); // NullPointerException here
        Toast.makeText(userRegistration1.this, "Getting the summary result: " +summaryResult, Toast.LENGTH_LONG).show();
ADM
  • 20,406
  • 11
  • 52
  • 83
John
  • 49
  • 7

1 Answers1

1

You are using the wrong intent at Sender Code. Remove that unnecessary intent. You need to use senderIntent.

   @Override
        public void onClick(View view) {

            
   Intent senderIntent = new Intent(getApplicationContext(), UserRegistration1.class);
   Bundle senderBundle = new Bundle();
   senderBundle.putString("summaryResult", summaryResult);

   senderIntent.putExtras(senderBundle);
   startActivity(senderIntent);

   Toast.makeText(getApplicationContext(), "It was sent: " + summaryResult, Toast.LENGTH_LONG).show();
   startActivity(senderIntent);
        
}});
Ticherhaz FreePalestine
  • 2,738
  • 4
  • 20
  • 46