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);
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!