SLaks 2013-07-29 08:00 采纳率: 0%
浏览 4602

在imageview.setBackgroundResource上的空指针

在布局上有一个imageview,名称是 footer.xml,实际上是给 listview 添加的一个 footer。我需要在 listview 的末尾动态的显示图像。我在java 文件中设置的 imageview 如下:

ImageView footerimage;
    View footerView = getLayoutInflater().inflate(R.layout.footer, null);//This is the footer layout which i have added to the listview
    footerimage = (ImageView)findViewById(R.id.im);
    footerimage.setBackgroundResource(images[i]);//images is an integer array which has drawable resources and i value is not null.
    lv.addFooterView(footerView, null, false);

在上面代码中的第四行获得一个空指针异常,我也把 images[i] 改成 R.drawable.someimage,但是 NPE 还是存在的,下面是 footer Layout:

<?xml version="1.0" encoding="utf-8"?>
<ImageView
    android:id="@+id/im"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"        
    android:contentDescription="@string/app_name" />

大家给予的任何建议都非常感谢!

  • 写回答

1条回答 默认 最新

  • JaveZh 2013-07-29 08:09
    关注
    footerimage = (ImageView)findViewById(R.id.im);
    

    改成:

    footerimage = (ImageView)footerView.findViewById(R.id.im);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题