ViewPager_Adapter 클래스의 생성자의 length는
bitmap 객체의 Arraylist.size()를 받습니다.(arraylist 길이요..)
뷰 페이져 화면에 뿌려지는 것까지는 제대로 작동합니다.
그런데.. 페이지를 한번 넘겨버리면 에러나면서 꺼져버리네요
public class ViewPager_Adapter extends PagerAdapter {
private Context mContext;
int length;
..생략..
public ViewPager_Adapter( Context context, int length ) {
mContext = context;
this.length = length;
}
public int getCount() {
return 26;
}
public Object instantiateItem(ViewGroup container, int position) {
Log.d("메시지","position ="+position);
// create a instance of the page and set data
ViewPager_Layout page = new ViewPager_Layout(mContext);
page.setImage(position);
container.addView(page, position);
return page;
}
public class ViewPager_Layout extends LinearLayout{
Bitmap_ArrayList arry=Bitmap_ArrayList.getInstance();
Context mContext;
ImageView iconImage;
public ViewPager_Layout(Context context) {
super(context);
init(context);
}
public ViewPager_Layout(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
mContext = context;
...생략...
}
public void setImage(int index) {
Log.d("메시지","get부분 바로 앞");
Log.d("메시지","인덱스값 "+index );
Bitmap bitmap = arry.get(index);
Log.d("메시지","get부분 바로 뒤");
iconImage.setImageBitmap(bitmap);
}
}
Log를 따라간 것입니다.)
D/메시지: position =0
D/메시지: get부분 바로 앞
D/메시지: 인덱스값 0
D/메시지: get부분 바로 뒤
D/메시지: position =1
D/메시지: get부분 바로 앞
D/메시지: 인덱스값 1
D/메시지: get부분 바로 뒤
D/메시지: position =2
D/메시지: get부분 바로 앞
D/메시지: 인덱스값 2
다음은 에러메시지입니다.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pc., PID: 3966
java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
저 메시지를 따라서 확인하면
Bitmap bitmap = arry.get(index);
코드가 3번째 호출될 때 에러가 나더라구요
제가 이해가 안되는건
list는 25번까지 갖고 있는데
왜 에러가나는지 모르겠네요...