Android Fragment setAdapter 报错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();
// 点
dots = new ArrayList();
dotList = new ArrayList();
dots.add(dot0);
dots.add(dot1);
dots.add(dot2);
dots.add(dot3);
dots.add(dot4);
adViewPager.setAdapter(new MyAdapter());// 设置填充ViewPager页面的适配器
// 设置一个监听器,当ViewPager中的页面改变时调用
adViewPager.setOnPageChangeListener(new MyPageChangeListener());
addDynamicView();
}
private class MyAdapter extends PagerAdapter {

    @Override
    public int getCount() {
        return adList.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView iv = imageViews.get(position);
        ((ViewPager) container).addView(iv);
        final AdDomain adDomain = adList.get(position);
        // 在这个方法里面设置图片的点击事件
        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 处理跳转逻辑
            }
        });
        return iv;
    }

adViewPager.setAdapter(new MyAdapter());报错

查看全部
qq_28186229
崔峰鸣
2016/06/29 04:16
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复