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;
}
}
可能是什么问题以及如何解决?
答案 0 :(得分:4)
试试这个
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.loafmaking_items, false);
工作解决方案:
按照Slenkra
View itemView = inflater.inflate(R.layout.loafmaking_items, container, false);