2014-04-04 53 views
-2

當我在異步任務的onPostexecute方法完成後將適配器設置爲viewpager時,我得到此異常並且應用程序強制關閉。 「ViewPager尚未綁定」ViewPager尚未綁定

我正在爲TabPage指標使用jakeWhartons Viewpager指標。

有沒有修復它?

code snippet。

public class MyDetailedActivity extends FragmentActivity { 
    ViewPager pager; 
    PageIndicator mIndicator; 
    ProgressBar progressBar1; 
    ProgressBar progressBar2; 
     public void onCreate(Bundle savedInstanceState) { 

    setContentView(R.layout.ac_image_pager); 
      progressBar1 = (ProgressBar)findViewById(R.id.progressBarPager1); 
    progressBar2 = (ProgressBar)findViewById(R.id.progressBarPager2); 

    progressBar1.setVisibility(View.VISIBLE); 
    progressBar2.setVisibility(View.VISIBLE); 

    //Declare Pagers & Indicators 
    //Pager-Top 
    pager = (ViewPager) findViewById(R.id.pager); 
    pager.setClipToPadding(false); 
    pager.setPageMargin(12); 
    //Indicator of Pager-Top 
    mIndicator = (TabPageIndicator)findViewById(R.id.indicator); 
      new PastEventFullDetailDownloader(past_event_id).execute(null,null,null); 
    } 

    private class PastEventFullDetailDownloader extends AsyncTask<String,String,  String> 
    { 

    protected String doInBackground(String... params) { 
    //Download data 
     } 
    protected void onPostExecute(String result) { 
      displayEvent(result); 
    } 
} 
void displayEvent(PastEventInfo event) 
{ 
    //hide the progressbars 
    progressBar1.setVisibility(View.GONE); 
    progressBar2.setVisibility(View.GONE); 

    //Set Up Adapter for First Pager ..Pass ImageUrsl Just Downloaded 
    pager.setAdapter(new ImagePagerAdapter(event.getEventImageUrsl())); 
    pager.setCurrentItem(pagerPosition); 
    mIndicator.setViewPager(pager); 
} 

}

enter image description here

+0

stacktrace和相關的代碼會幫助 – donfuxx

+0

@donfuxx我已經添加了代碼片段和異常堆棧跟蹤。請仔細看看 – zee

+0

@donfuxx你有什麼想法隊友嗎? ( – zee

回答

0

您CA檢查TabPageIndicator.javaJakeWharton

https://github.com/JakeWharton/Android-ViewPagerIndicator/blob/master/library/src/com/viewpagerindicator/TabPageIndicator.java

@Override 
public void setCurrentItem(int item) { 
    if (mViewPager == null) { 
     throw new IllegalStateException("ViewPager has not been bound."); 
    } 
    mSelectedTabIndex = item; 
    mViewPager.setCurrentItem(item); 

    final int tabCount = mTabLayout.getChildCount(); 
    for (int i = 0; i < tabCount; i++) { 
     final View child = mTabLayout.getChildAt(i); 
     final boolean isSelected = (i == item); 
     child.setSelected(isSelected); 
     if (isSelected) { 
      animateToTab(item); 
     } 
    } 
} 

這個錯誤被拋出,WH en mViewPager爲空。你需要交叉檢查這一點。

+0

)我知道,我有幾個階段交叉檢查viewpager狀態..但它不是這種情況..那就是爲什麼我對這個問題感到困惑 – zee

+0

檢查最後的評論在這裏 - https: //github.com/JakeWharton/Android-ViewPagerIndicator/issues/155 –

+0

我沒有得到它..我測試了應用程序的物理設備..仍然問題依然存在..anyways thx .. :) – zee

相關問題