2017-04-27 119 views
0

我創建了一個包並將值放到它上面並跳到下一個活動,出於某種原因它無法在另一端獲取值,它說空對象的引用,但我有我的價值觀和我在一起,無法將值從一個活動發送到Android中的其他活動

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"); 
+0

你在哪裏有其他活動的代碼。在onCreate。另外使用調試器應該會有所幫助 – Raghunandan

+0

你如何獲得第二項活動中的第一項活動?請張貼您的日誌。 –

+0

我已經把它放在OnCreate之外,我猜這就是問題 – Venky

回答

4

試試這個:

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方法

​​
+0

請檢查更新回答 –

+0

啊,應該在OnCreate裏面? – Venky

+0

是.................. –

0

請先整數轉換值的字符串,然後將其發送到另一個活動。

 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)); 
相關問題