0
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    ImageView iv_images;

    final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = inflater.inflate(R.layout.imageadapter1, null);

    iv_images = (ImageView) convertView.findViewById(R.id.iv_images1);

    iv_images.setImageResource(images[position]);

    return convertView;
}

java.lang.OutOfMemoryError: Failed to allocate a 9042060 byte allocation with 8030424 free bytes and 7MB until OOM

2 Answers 2

1

You could just use a smaller image.

  1. Google have actually published a guide on avoiding OutOfMemoryErrors here which will help a lot, though I had to use a smaller image size as well.
  2. One method that will almost definitely work is to set android:largeHeap="true" in your manifest, between your application tags. This will increase your heap size, but may make your app lag a little.
  3. Make use of WebP image for loading if you had large number of image.

You may, try this link https://developer.android.com/topic/performance/graphics/load-bitmap

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

1 Comment

plse check this link, developer.android.com/topic/performance/graphics/load-bitmap , may be help you
0

You can use libraries such as Picasso

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    ImageView iv_images;

    final LayoutInflater inflater = (LayoutInflater) 
    mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = inflater.inflate(R.layout.imageadapter1, null);

    iv_images = (ImageView) convertView.findViewById(R.id.iv_images1);

    Picasso.get()
       .load(images[position])
       .resize(YOUR_WIDTH, YOUR_HEIGHT)
       .centerCrop()
       .into(iv_images)

    return convertView;
}

Don't forgot to add dependecies.

Gradle:

implementation 'com.squareup.picasso:picasso:2.71828'

Maven:

<dependency>
  <groupId>com.squareup.picasso</groupId>
  <artifactId>picasso</artifactId>
  <version>2.71828</version>
</dependency>

2 Comments

I'm glad it helped you. Feel free to ask if you have questions about it.
Thanks a Lot Dude...It's Working

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.