-3

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

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

}
4

1 回答 1

0

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

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

 name = (TextView)getActivity().findViewById(R.id.name);
于 2013-10-25T12:33:53.140 回答