<이미지 변수배열>
private Integer[] gridviewimage = {R.drawable.food_01 ,R.drawable.food_02,R.drawable.food_03,R.drawable.food_04,R.drawable.food_05
, R.drawable.food_06,R.drawable.food_07};
<gridview Adapter소스>
public class gridAdapter extends BaseAdapter
{
LayoutInflater inflater2;
public gridAdapter()
{
inflater2 = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return apps.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return apps.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if(convertView == null)
{
convertView = inflater2.inflate(R.layout.image_adapter, parent,false);
}
final ResolveInfo info = apps.get(position);
ImageView imageView = (ImageView) convertView.findViewById(R.id.iv001);
if(position <= gridviewimage.length)
{
imageView.setImageResource(gridviewimage[position]);
}
imageView.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
return convertView;
}
}
밑줄 친 부분대로 실행을 하면 로그창에 오류내용이
java.lang.ArrayIndexOutOfBoundsException: length=7; index=7
이런식으로 나옵니다.
position으로 들어오는값이 배열의 길이보다 커서 그런거같은데 어떤식으로 해결을 해야하나요?도움 부탁드립니다