java - 通过 android studio 中的意图发送 MultiMap 类型的数据结构
问题描述
我必须为我的 android 应用程序创建一个“multimap”类型的数据结构,看起来像这样
HashMap<Integer, String []> sampleStorage = new HashMap<Integer, String []>
我试图通过几个活动传递它,但它未能传递给第一个活动。我知道这一点是因为数据在它创建的活动中可用,但在我将意图传递给的活动中不可用。
我正在使用此代码将其添加到意图并发送它
Intent intent = new Intent(this, MyActivity.class);
Bundle args = new Bundle();
args.putSerializable("sampleStorage", (Serializable)sampleStorage);
intent.putExtra("BUNDLE", args);
这是我用来检索它的代码
Intent intent = getIntent();
Bundle args = intent.getBundleExtra("BUNDLE");
sampleStorage = (HashMap<Integer, String []>) args.getSerializable("sampleStorage");
当我尝试在第二个活动中访问它时引发的错误是 NullPointerError 所以它似乎甚至没有进入第二个活动。任何帮助将不胜感激,在此先感谢您。
解决方案
因此,经过几天的代码搜索,我发现有一个 sampleStorage 的辅助声明覆盖了我的初始哈希映射。抱歉,我最初没有提供足够的代码让某人首先正确回答问题。
推荐阅读
- javascript - 在 componentDidMount 中处理多个 axios get 请求
- statistics - MCMC 如何帮助贝叶斯推理?
- c# - 使用 ReactiveUI 绑定到组合框中的选定项目
- razor - ASP.NET Core 2.2 剃刀视图中的操作按钮
- python - python在windows中检索和修改mp4文件属性
- typescript - 如何正确计算打字稿日期Angular的月差
- python - Python 函数未从 cmd 运行,路径变量已定义且 Python 控制台正常运行
- ruby-on-rails - 如何修复视图 Ruby 中的“NoMethodError”错误
- leaflet - 标记移动时传单路由.控制更新
- python - 如何结合使用 for 循环和 print 语句