Android imageswitcher上的不可访问语句

Android imageswitcher上的不可访问语句,android,fragment,imageswitcher,Android,Fragment,Imageswitcher,我的代码是在定义图像切换器的行上有一个无法访问的语句错误 public class mainFragment extends Fragment implements ViewSwitcher.ViewFactory{ private OnFragmentInteractionListener mListener; public mainFragment() { // Required empty public constructor } int

我的代码是在定义图像切换器的行上有一个无法访问的语句错误

public class mainFragment extends Fragment implements ViewSwitcher.ViewFactory{

    private OnFragmentInteractionListener mListener;

    public mainFragment() {
        // Required empty public constructor
    }
    int cnt= 0;
    int imgs[]={
            R.drawable.mah_121,
            R.drawable.tamashagar_207,
            R.drawable.tandorosti_149

    };
    ImageSwitcher imgSwitcher;
    //final ImageView imageView;
    //ImageView imageView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_main, container, false);

        imgSwitcher = (ImageSwitcher) getView().findViewById(R.id.imageSwitcher);

        imgSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                ImageView imageView = new ImageView(getActivity());
                imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                //imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
                return imageView;
            }

        });
        imgSwitcher.setImageResource(imgs[cnt]);



    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnFragmentInteractionListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    @Override
    public View makeView() {
        return null;
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p/>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        public void onFragmentInteraction(Uri uri);
    }
}

在imageview定义中使用getActivity后,出现了“error unreachable Statement”问题,这是因为您在开始时从该方法返回:
返回充气机。充气(R.layout.fragment_main,容器,假)

尝试:
视图=充气机。充气(R.layout.fragment_main,容器,false);
imgSwitcher=(ImageSwitcher)view.findViewById(R.id.ImageSwitcher)

然后作为该函数的最后一行:
返回视图

返回后,您不能有任何内容(注释和空白除外)


值得将与
imgSwitcher
相关的代码移动到
onViewCreated

中。当然,这是在方法之外的<代码>imgSwitcher.setImageResource(imgs[cnt])})恕我直言,如果你不能只看一眼就能看到它,那么在构建应用程序之前,你需要做一些更基础的Java研究,因为对于简单的东西,你会遇到一个又一个问题`
imgSwitcher = (ImageSwitcher) getView().findViewById(R.id.imageSwitcher);