サイズを指定して配列を初期化してもこの例外が発生するのはなぜわかりませんか。配列のサイズを増やそうとすると、この例外が発生します。これは私のコードです。誰でも私が間違っていることを示唆することはできますか?サイズが配列の初期化にもかかわらずArrayIndexOutOfBoundsExceptionが発生する理由
public class MsgAdapter extends BaseAdapter {
public String msgs[]=new String[150];
public Activity context;
public LayoutInflater inflater;
int count=16;
public MsgAdapter(Activity context,String[] msgs) {
super();
this.context = context;
this.msgs = msgs;
this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public static class ViewHolder
{
TextView msgView;
ImageView b;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
Log.v("count", ""+msgs.length);
return msgs.length+16;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
View v;
LayoutInflater inflater = context.getLayoutInflater();
if(convertView==null){
convertView = inflater.inflate(R.layout.msg_list, null);
holder = new ViewHolder();
holder.msgView=(TextView)convertView.findViewById(R.id.msgtext);
holder.b=(ImageView)convertView.findViewById(R.id.sms);
convertView.setTag(holder);
}
else
{
holder=(ViewHolder)convertView.getTag();
}
holder.b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", holder.msgView.getText().toString());
sendIntent.setType("vnd.android-dir/mms-sms");
v.getContext().startActivity(sendIntent);
}
});
holder.msgView.setText(msgs[position]);//the exception occurs here
return convertView;
}
}
その明確なNWを願っていますなぜこのエラーが発生しているのですか? – RobinHood