qq_28186229
崔峰鸣
2016-06-29 07:40

Android java.lang.NullPointerException

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
initAdData();
View view = inflater.inflate(R.layout.fragment_travel, container, false);

    dot0 = view.findViewById(R.id.v_dot0);
    dot1 = view.findViewById(R.id.v_dot1);
    dot2 = view.findViewById(R.id.v_dot2);
    dot3 = view.findViewById(R.id.v_dot3);
    dot4 = view.findViewById(R.id.v_dot4);
    tv_title = (TextView)view.findViewById(R.id.tv_title);
    adViewPager = (ViewPager)this.getActivity().findViewById(R.id.vp);

    return view;
}
    private void initAdData() {
    // 广告数据
    adList = getBannerAd();
    imageViews = new ArrayList<ImageView>();
    // 点
    dots = new ArrayList<View>();
    dotList = new ArrayList<View>();
    dots.add(dot0);
    dots.add(dot1);
    dots.add(dot2);
    dots.add(dot3);
    dots.add(dot4);
    ViewPager adViewPager = new ViewPager(getActivity());
    adViewPager.setAdapter(new MyAdapter());// 设置填充ViewPager页面的适配器
    // 设置一个监听器,当ViewPager中的页面改变时调用
    adViewPager.setOnPageChangeListener(new MyPageChangeListener());
    addDynamicView();
}
    private void addDynamicView() {
    // 动态添加图片和下面指示的圆点
    // 初始化图片资源
    for (int i = 0; i < adList.size(); i++) {
        ImageView imageView = new ImageView(getActivity());
        // 异步加载图片
        mImageLoader.displayImage(adList.get(i).getImgUrl(), imageView, options);
        imageView.setScaleType(ScaleType.CENTER_CROP);
        imageViews.add(imageView);
        dots.get(i).setVisibility(View.VISIBLE);//这行java.lang.NullPointerException
        dotList.add(dots.get(i));
    }
}

    dots.get(i).setVisibility(View.VISIBLE);//这行java.lang.NullPointerException
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

7条回答