0

I am developing an application in which I have parsed Json of public facebook profile. I got String of imageurl and saved them into ArrayList and then implemented in listView. everything is going fine but sometimes my application is crashing by giving an error as "array index out of bound" or "memory space exception". unable to resolve this problem. help me out. thanks in advance.

I am attaching my code also.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = View.inflate(SocialActivity.this, R.layout.facebook_row, null);
    ImageView iv_user = (ImageView)row.findViewById(R.id.iv_user_pic);
    TextView tv_title, tv_description, tv_time;
    tv_title = (TextView)row.findViewById(R.id.tv_title);
    tv_description = (TextView)row.findViewById(R.id.tv_discription);
    tv_time = (TextView)row.findViewById(R.id.tv_time);
    Button btn_count = (Button)row.findViewById(R.id.btn_arrow);
    //bitmap = DownloadImage(alJson.get(position).strPicUrl);
    tv_title.setText(alJson.get(position).strName);
    tv_description.setText(alJson.get(position).strMessage);
    tv_time.setText(alJson.get(position).strDate);
    btn_count.setText(alJson.get(position).strCount);
    if((alJson.get(position).strPicUrl).equals(null){
        iv_user.setBackgroundResource(R.drawable.contact_img);
    } else{
        iv_user.setImageBitmap(al_bitmap.get(position));
    }
    return row;
}
3
  • resolved this problem by placing by placing the code "if((alJson.get(position).strPicUrl) == null)" at the place of "if((alJson.get(position).strPicUrl).equals(null)" Commented Jun 27, 2012 at 14:18
  • but now facing errors which are " ERROR/dalvikvm-heap(7936): 453152-byte external allocation too large for this process." " ERROR/dalvikvm(7936): Out of memory: Heap Size=15303KB, Allocated=13242KB, Bitmap Size=9311KB " Commented Jun 27, 2012 at 14:18
  • Handling bitmaps is never easy in Android. You can find a lot of information about it here on stackoverflow... Commented Jun 28, 2012 at 9:24

3 Answers 3

1

Make sure the alJson.size() is not 0
and also try logging alJson.size() and position to see if there's something wrong with these values

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe possible your ArrayList alJson is empty so check before using it as:

int listsize = alJson.size();
if(listsize>=0 && listsize<=position)
{
    tv_title.setText(alJson.get(position).strName);
    tv_description.setText(alJson.get(position).strMessage);
    tv_time.setText(alJson.get(position).strDate);
    btn_count.setText(alJson.get(position).strCount);

    if((alJson.get(position).strPicUrl).equals("null"){
     iv_user.setBackgroundResource(R.drawable.contact_img);
    }
    else{

    iv_user.setImageBitmap(al_bitmap.get(position));

    }
}
else
{
 //DO SOME CODE HERE
}

Comments

0

Making position variable final solved my problem

public View getView(final int position, View convertView, ViewGroup parent)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.