1

皆さんこんにちは!私はこのような同様のプログラムを作成しようとしています: http://www.androidbegin.com/tutorial/android-viewpager-gallery-images-and-texts-tutorial/ しかし、プログラムを実行すると、常に次のエラーが発生しますコード:

 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;
    }

}

何が問題で、どうすれば修正できますか?

4

1 に答える 1

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);
于 2013-06-25T09:59:21.980 に答える