2015-01-31 3 views
1

У меня есть некоторые проблемы с использованием SwipableTabsLayout вместе с SwipeRefreshLayout. Всякий раз, когда я запустить приложение, проверьте напряжение, чтобы обновить, приложение Аварии:SwipableRefreshLayout внутри Slidingtablayout crashes app

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) 

У меня есть SwipableTabLayout с 3-мя вкладками; для каждой из вкладок У меня есть фрагмент Адаптер вид пейджера раздувает представление для выбранной вкладки, например так:

@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> 

Любые намеки о том, как это исправить, или почему это происходит сбой является ppreciated. Спасибо!

+0

Возможный дубликат [SwipeRefreshLayout с EmptyView nullPointerException] (http://stackoverflow.com/questions/24742031/swiperefreshlayout-with-emptyview-nullpointerexception) – corsair992

ответ

0

Ну, я просто отсутствовал mSwipeRefresh.setOnRefreshListener (это); Это мой фрагмент, реализующий SwipeRefreshLayout.OnRefreshListener.