Slidingtablayout 内的 SwipableRefreshLayout 使应用程序崩溃

SwipableRefreshLayout inside Slidingtablayout crashes app

我在将 SwipableTabsLayout 与 SwipeRefreshLayout 一起使用时遇到了一些问题。 每当我启动应用程序时,测试下拉刷新,应用程序崩溃:

01-31 23:00:49.376    2181-2181/com.larswise.ru2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.larswise.ru2, PID: 2181
    java.lang.NullPointerException
            at android.support.v4.widget.SwipeRefreshLayout.startRefresh(SwipeRefreshLayout.java:530)
            at android.support.v4.widget.SwipeRefreshLayout.onTouchEvent(SwipeRefreshLayout.java:484)
            at android.view.View.dispatchTouchEvent(View.java:8112)

我有一个带有 3 个选项卡的 SwipableTabLayout;对于每个选项卡,我都有一个片段 视图寻呼机适配器为所选选项卡扩充视图,如下所示:

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int posFragment;
    switch(position) {
        case 0: posFragment = R.layout.root_feed_layout; break;
        case 1: posFragment = R.layout.discover_view; break;
        case 2: posFragment = R.layout.settings_view; break;
        default: posFragment = R.layout.feed_layout;
    }

    View view = getActivity().getLayoutInflater().inflate(posFragment,
            container, false);
    container.addView(view);
    return view;
}

在其中一个布局中,"root_feed_layout",我有一个片段参考:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="com.larswise.ru2.fragments.FeedFragment"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:id="@+id/feed_root_layout">

    <fragment
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:name="com.larswise.ru2.fragments.FeedFragment"/>

</RelativeLayout>

这是片段的布局,"FeedFragment" 我有 SwipeRefreshLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/feed_root"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:layout_height="fill_parent">
    <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_paren"
        android:id="@+id/swipe_refresh_layout">
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff">

            <ListView
                android:id="@+id/post_list"
                android:layout_width="fill_parent"
                android:layout_height="0dip"
                android:layout_weight="2"
                android:cacheColorHint="#000000"
                android:divider="#D5DDDE"
                android:dividerHeight="1dp"
                android:drawSelectorOnTop="false"
                android:focusableInTouchMode="false"
                android:footerDividersEnabled="false"
                android:headerDividersEnabled="true"
                android:listSelector="@android:color/transparent" />

            </ScrollView>
        </android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
    android:id="@+id/footer"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    android:gravity="center|bottom">

        <Button
            android:id="@+id/newButton"
            style="@style/BottomBarButton"
            android:text="@string/menu_new" />
        <View
            android:layout_width="1dip"
            android:layout_height="35dp"
            />
        <Button
            android:id="@+id/extraButton"
            style="@style/BottomBarButton"
            android:text="@string/menu_test" />
</LinearLayout>
</LinearLayout>

感谢任何有关如何解决此问题或失败原因的提示。 谢谢!

好吧,我只是想念 mSwipeRefresh.setOnRefreshListener(this); 这是我的片段,实现 SwipeRefreshLayout.OnRefreshListener.