1
Hy everyone! 我試圖做這樣一個類似的計劃:http://www.androidbegin.com/tutorial/android-viewpager-gallery-images-and-texts-tutorial/ 但是當我運行該程序,我總是碰到下面的錯誤代碼:Android stackoverflow錯誤頁面適配器
06-25 09:51:44.507: E/AndroidRuntime(721): FATAL EXCEPTION: main 06-25
09:51:44.507: E/AndroidRuntime(721): java.lang.StackOverflowError
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.View.onWindowVisibilityChanged(View.java:4042) 06-25
09:51:44.507: E/AndroidRuntime(721): at
android.view.View.dispatchAttachedToWindow(View.java:6159) 06-25
09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1122)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1127)
06-25 09:51:44.507: E/AndroidRuntime(721): at android.
我PagerAdapter類:
public class LoafMakingPageAdapter extends PagerAdapter {
Context context;
int[] pictures;
LayoutInflater inflater;
public LoafMakingPageAdapter(Context context,int[] pictures){
this.context = context;
this.pictures = pictures;
}
@Override
public int getCount() {
return pictures.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imgLoaf;
TextView textLoaf;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.loafmaking_items, container);
textLoaf = (TextView) itemView.findViewById(R.id.loaf_text);
imgLoaf = (ImageView) itemView.findViewById(R.id.loaf_image);
imgLoaf.setImageResource(pictures[position]);
container.addView(itemView);
return itemView;
}
}
有什麼可以該問題以及如何解決?
那麼這個片段一點點編輯解決我的問題,但你能告訴我爲什麼得到這些錯誤? 修改後的代碼:'查看itemView = inflater.inflate(R.layout.loafmaking_items,container,false);' – Slenkra
如果它解決了您的問題,請選擇它作爲您問題的答案。實際上這是你必須做的過程。我只知道這一點。 –
感謝您發佈solution.It是有幫助的! –