Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓4.0标签滑动导致崩溃_Android_User Interface_Tabs_Swipe - Fatal编程技术网

Android 安卓4.0标签滑动导致崩溃

Android 安卓4.0标签滑动导致崩溃,android,user-interface,tabs,swipe,Android,User Interface,Tabs,Swipe,我添加了一个新活动,并将其设置为导航类型中的选项卡滑动。 到目前为止还不错,但当我滑动到另一个选项卡时,它崩溃并给出了这个错误(但它至少显示了布局): 切换选项卡: @Override public Fragment getItem(int position) { // getItem is called to instantiate the fragment for the given page. // Return a Dumm

我添加了一个新活动,并将其设置为导航类型中的选项卡滑动。 到目前为止还不错,但当我滑动到另一个选项卡时,它崩溃并给出了这个错误(但它至少显示了布局):

切换选项卡:

@Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a DummySectionFragment (defined as a static inner class
            // below) with the page number as its lone argument.
            Fragment fragment = null;           
            switch (position) {
            case 0:
                fragment = new AddExpense();
                break;
            case 1:
                fragment = new AddIncomeSource();
                break;
            default:
                break;
            }
            return fragment;
        }
选项卡的内部类(每个选项卡的每个类):


你确定位置永远不会超过1吗?我猜是你的碎片制造开关/箱子出错了。尝试将一个片段添加到默认值中,看看崩溃是否消失。很抱歉延迟重播,非常感谢!问题是我的开关盒和你说的一模一样,所以我添加了一个默认片段。
@Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a DummySectionFragment (defined as a static inner class
            // below) with the page number as its lone argument.
            Fragment fragment = null;           
            switch (position) {
            case 0:
                fragment = new AddExpense();
                break;
            case 1:
                fragment = new AddIncomeSource();
                break;
            default:
                break;
            }
            return fragment;
        }
public static class AddExpense extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        public static final String ARG_SECTION_NUMBER = "section_number";

        public AddExpense() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {

            View v = inflater.inflate(R.layout.add_expense, null);
            return v;
        }
    }

    public static class AddIncomeSource extends Fragment {
        public static final String ARG_SECTION_NUMBER = "section_number";

        public AddIncomeSource() {
        }
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {

            View v = inflater.inflate(R.layout.add_income, null);
            return v;
        }
    }