0

I've created a bundle and put values onto it and jumped to the next activity,for some reason its not able to get the values at the other end,it says null object reference,but i have my values with me,

public void rsa_key(String s){
        Intent intent = new Intent(getBaseContext(), SomeClass.class);
        //Create the bundle
        Bundle bundle = new Bundle();

//Add your data to bundle
        //String hello=null;
        bundle.putString("id", txId);
        bundle.putString("cardamt", cardAmount);
        bundle.putString("cardconv", cardConvFee);
//Add the bundle to the intent
        intent.putExtras(bundle);




        startActivity(intent);

    }

In the other activity

String txId = bundle.getString("id");
        String cardConvFee = bundle.getString("cardconv");
        String cardAmount = bundle.getString("cardamt");
Venky
  • 1,929
  • 3
  • 21
  • 36

2 Answers2

4

try this:

public void rsa_key(String s){
        Intent intent = new Intent(getBaseContext(), SomeClass.class);

        //String hello=null;
        intent.putExtras("id", txId);
        intent.putExtras("cardamt", cardAmount);
        intent.putExtras("cardconv", cardConvFee);





        startActivity(intent);

    }

in your second activity onCreate method

Bundle bundle = getIntent().getExtras();
String txId = bundle.getString("id");
        String cardConvFee = bundle.getString("cardconv");
        String cardAmount = bundle.getString("cardamt");
Bhupat Bheda
  • 1,968
  • 1
  • 8
  • 13
0

Please convert integer values in string first and then send it to another activity.

        Bundle bundle = new Bundle();

        //Add your data to bundle
        //String hello=null;
        bundle.putString("id", String.valueOf(txId));
        bundle.putString("cardamt", String.valueOf(cardAmount));
        bundle.putString("cardconv", String.valueOf(cardConvFee));
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66