android 空指针错误
今天运行代码的时候遇到了空指针错误,错误发生在:
findImageView(queue);
queue在前面有定义:
int[] queue = { R.drawable.p1, R.drawable.p2, R.drawable.p3, R.drawable.p4,
R.drawable.p5, R.drawable.p6, R.drawable.p7, R.drawable.p8,
R.drawable.p9, 1 };
还有一个空指针发生在:
Drawable pic1 = getResources().getDrawable(queue[0]);
iv_1 = (ImageView) this.findViewById(R.id.ImageView01);
iv_1.setImageDrawable(pic1);
上面的代码我单独的跑是没有问题的,可是在mainActivity中设置Intent,跳转到上面这个Activity后就发生了这样的错误,谁能解释一下?

解决方案 »

  1.   

    是不是你跳转后的activity的view不是ImageView01所在的view?
      

  2.   

    把layout中ImageView01的宽高都改成自适应,不要用fill_parent.
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
      

  3.   

    debug,设断点,跟踪问题,找出空指针针!
      

  4.   

    问题解决了,原来是setContentView的时候错了,所以导致了空指针的错误,谢谢各位
      

  5.   

    setContentView里面设置了错误的xml文件,所以导致空指针