更改 ViewPager 中特定页面中的 ImageView 源 Android

Change ImageView source in specific page in ViewPager Android

我想在视图寻呼机的特定页面中更改图像资源。这就是我所做的。

这是 onCreate activity ...

        ((PlaceholderFragment)mSectionsPagerAdapter.getItem(0)).updateImage(R.drawable.help1);
        ((PlaceholderFragment)mSectionsPagerAdapter.getItem(1)).updateImage(R.drawable.help2);
        ((PlaceholderFragment)mSectionsPagerAdapter.getItem(2)).updateImage(R.drawable.help3);
        ((PlaceholderFragment)mSectionsPagerAdapter.getItem(3)).updateImage(R.drawable.help4);

这是片段class...

public static class PlaceholderFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private static final String ARG_SECTION_NUMBER = "section_number";

    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    public static PlaceholderFragment newInstance(int sectionNumber) {
        PlaceholderFragment fragment = new PlaceholderFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_help, container, false);
        ImageView imageView = (ImageView) rootView.findViewById(R.id.imageHelp);
        imageView.setImageResource(R.drawable.help4);
        return rootView;
    }

    public void updateImage(int image){
        ImageView imageView = (ImageView) getView().findViewById(R.id.imageHelp);
        imageView.setImageResource(image);

    }
}

但不知何故它仍然给我错误空指针异常。我怎么想念 之前谢谢你,请帮助我 :) 我在这里呆了大约 2 个小时。

// declare rootView as global variable

public void updateImage(int image){
    ImageView imageView = (ImageView) rootView.findViewById(R.id.imageHelp);
    imageView.setImageResource(rootView);
}