毕加索:java.lang.IllegalArgumentException:Target不能为null

时间:2016-03-14 23:16:47

标签: android android-fragments android-viewpager picasso

我正在使用ViewPager来显示欢迎,注册和其他一些屏幕。这些屏幕是由FragmentStatePagerAdapter控制的片段:

private static class TourPagerAdapter extends FragmentStatePagerAdapter {
        public TourPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            WellcomeTourFragment ta = null;
            switch (position) {
                case 0:
                    ta = WellcomeTourFragment.newInstance(R.layout.welcome_fragment);
                    break;
                case 1:
                    ta = WellcomeTourFragment.newInstance(R.layout.signup_fragment);
                    break;

第一个片段(WellcomeFragment)显示了使用毕加索库从互联网加载的一些视图和背景图像:

private ImageView bkgImage;

    public static WellcomeTourFragment newInstance(int layoutId){
            WellcomeTourFragment pane = new WellcomeTourFragment();
            Bundle args = new Bundle();
            args.putInt(LAYOUT_ID, layoutId);
            pane.setArguments(args);
            return pane;
        }

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            final ViewGroup rootView = (ViewGroup) inflater.inflate(getArguments().getInt(LAYOUT_ID, -1), container, false);
            this.bkgImage = (ImageView) rootView.findViewById(R.id.imgView_Background);
            return rootView;
        }

        @Override
        public void onViewCreated(View view,  Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);
            Picasso.with(getActivity())
                    .load(IMG_uRL)
                   .into(this.bkgImage);
        }

我的问题在于,我正在

  

java.lang.IllegalArgumentException:Target不能为null。

我确信ImageView确实在我的welcome_fragment布局中退出。但实际上不知道是什么让目标成为空。

1 个答案:

答案 0 :(得分:0)

您确定正确的布局是否正在膨胀?尝试调试并在rootView充气后查看rootView。调用newInstance方法时,是否可能包含错误的布局ID?