Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting ArrayIndexOutOfBoundsException in spite of initializing the array with a size
    primarykey
    data
    text
    <p>I'm unable to find out why am I getting this exception despite initializing the array with a size. When I try to increase the size of the array this exception occurs.Here is my code. Can anybody suggest what am I doing wrong?</p> <pre><code>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; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload