【发布时间】:2014-09-05 04:59:47
【问题描述】:
我正在将 hashmap 中的数据从子活动发送回父活动
这是我的代码 儿童活动
private void sendDataToPrevPg(HashMap<String, String> hm) {
// Send to previous activity page
Bundle bndle = new Bundle();
bndle.putSerializable("stockList", (Serializable) hm);
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("stkList",bndle);
setResult(RESULT_OK, intent);
this.finish();
}
在父母中
@SuppressWarnings("unchecked")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK ) {
if (data.hasExtra("stkList")) {
Bundle wrapper = getIntent().getBundleExtra("stkList");
HashMap<String, String> myClass3 = (HashMap<String, String>) wrapper.getSerializable("stkList");
System.out.println("...serialized data4.."+myClass3);
}
}
}
在行显示错误
HashMap<String, String> myClass3 = (HashMap<String, String>) wrapper.getSerializable("stkList");
Logcat:: 引起:java.lang.NullPointerException
如何在 hashmap 中发送数据?到父活动
【问题讨论】:
-
这不是 serealize 的问题,只是将数据存储到公共类并使用它并从中删除
-
@user3811114 thnks 但在 logger sysout 语句中仍然 thr 为空
-
见下文,添加示例代码供您参考。
标签: android