2016-03-14 65 views
0

我使用ViewPager顯示歡迎,註冊和其他一些屏幕。這些屏幕是由FragmentStatePagerAdapter控制片段:Picasso:java.lang.IllegalArgumentException:目標不能爲空

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:目標不能爲空。

我確定ImageView確實退出了我的welcome_fragment佈局。但真的不知道是什麼讓目標爲空。

+0

請包含您的welcome_fragment佈局 –

+0

您確定'rootView.findViewById(R.id.imgView_Background)'不會返回null嗎? –

回答

0

您確定正確的佈局正在充氣嗎?嘗試調試並在充氣後查看rootView。當你調用你的newInstance方法時,你是否可能包含錯誤的佈局ID?