head.setBackgroundResource(R.drawable.head);
这一句的时候抛异常了
java.lang.NullPointerException

原来:如果include指定了id的话,就不能直接把它里面的控件当成主xml中的控件来直接获得了,必须先获得这个xml布局文件,再通过布局文件findViewById来获得其子控件。
代码如下
View layout = getLayoutInflater().inflate(R.layout.head, null);
RelativeLayout head= (RelativeLayout)layout.findViewById(R.id.index_linear_foot);
//设置背景图片
head.setBackgroundResource(R.drawable.head);

相关文章:

  • 2021-11-03
  • 2021-09-05
  • 2022-02-26
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2021-06-14
猜你喜欢
  • 2021-12-24
  • 2021-12-09
  • 2022-02-25
  • 2022-01-23
  • 2021-09-21
相关资源
相似解决方案