【问题标题】:Can't retrieve value from Bundle android无法从 Bundle android 中检索值
【发布时间】:2015-02-03 12:55:03
【问题描述】:

在我的片段中的 onCreateView 方法中,我使用以下代码检索为片段设置的 Bundle:

Bundle args = getArguments();
String value = args.getString("fixedExpenseId");

但不知何故,当我运行我的代码时,该值为 null。

当我调试我的程序时,我会检索以下变量:

如您所见,我使用的密钥与 Bundle 中的相同。

我怎么可能在我的

中检索 null

价值

变量?

【问题讨论】:

  • 显示您使用setArguments设置Bundle的代码
  • 你在使用 DialogFragment 吗?

标签: android android-fragments fragment bundle getstring


【解决方案1】:

只看截图,看起来你切换了键和值变量。您将键“2”设置为“fixedExpenseId”,而不是将键“fixedExpenseId”设置为“2”。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。只需检查您是否将正确的值与正确的键捆绑在一起,即在您的情况下为fixedExpenseId

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-02
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多