无法在Android中将值从一个活动发送到另一个活动

无法在Android中将值从一个活动发送到另一个活动,android,android-bundle,Android,Android Bundle,我已经创建了一个bundle并将值放在它上面,然后跳到下一个活动,由于某种原因,它无法在另一端获取值,它表示空对象引用,但我随身携带我的值 public void rsa_key(String s){ Intent intent = new Intent(getBaseContext(), SomeClass.class); //Create the bundle Bundle bundle = new Bundle(); //Add your

我已经创建了一个bundle并将值放在它上面,然后跳到下一个活动,由于某种原因,它无法在另一端获取值,它表示空对象引用,但我随身携带我的值

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);

    }
在另一项活动中

String txId = bundle.getString("id");
        String cardConvFee = bundle.getString("cardconv");
        String cardAmount = bundle.getString("cardamt");
试试这个:

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);

    }
在第二个活动onCreate方法中

Bundle bundle = getIntent().getExtras();
String txId = bundle.getString("id");
        String cardConvFee = bundle.getString("cardconv");
        String cardAmount = bundle.getString("cardamt");
试试这个:

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);

    }
在第二个活动onCreate方法中

Bundle bundle = getIntent().getExtras();
String txId = bundle.getString("id");
        String cardConvFee = bundle.getString("cardconv");
        String cardAmount = bundle.getString("cardamt");

请先转换字符串中的整数值,然后将其发送到其他活动

        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));

请先转换字符串中的整数值,然后将其发送到其他活动

        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));

您在其他活动中的代码在哪里。立即创建。此外,使用调试器应该有助于您如何在第二个活动中获得第一个活动的捆绑包?也请发布你的日志。我已经把它放在了OnCreate之外,我想这就是问题所在。你在其他活动中的代码在哪里。立即创建。此外,使用调试器应该有助于您如何在第二个活动中获得第一个活动的捆绑包?也请发布你的日志。我已经在创建时将其放在了外部,我想这就是问题所在。请检查更新的答案啊,它应该在创建时的内部??是的………请检查更新的答案啊,它应该在创建时的内部??是的。。。。。。。。。。。。。。。。。。