【问题标题】:Assign textview value from a hashmap string从 hashmap 字符串分配 textview 值
【发布时间】:2013-10-25 11:18:09
【问题描述】:

我的程序有问题,我正在尝试为我的文本视图名称设置一个动态值,分配给它的名称将来自地图(见下文)。我尝试时似乎很好在日志猫上打印值,但是当我必须把它放在文本视图本身上时,它变为空.. 谢谢

protected void setMap(HashMap<String, String> map) {

    String value=map.get("key");
    //printing on logcat works fine
    System.out.println(value);
    //name is a TextView, I initialized it on Oncreate()
    name.setText(value);
    //the setText causes NullPointerException

}

【问题讨论】:

  • 不是值,而是文本字段引用(例如name null
  • 你在哪里定义name
  • name = (TextView) findViewById(R.id.name);
  • 我在这里帮助我的朋友。干草

标签: android nullpointerexception android-activity hashmap


【解决方案1】:

由于您提供的信息很少,因此这或多或少是在黑暗中做空。

但是在具有setMap 方法的片段的onCreateView() 中尝试以下操作:

 name = (TextView)getActivity().findViewById(R.id.name);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    相关资源
    最近更新 更多